Results 1 to 4 of 4

Thread: Hibernate and Acegi caching

  1. #1
    Join Date
    Jun 2007
    Posts
    25

    Default Hibernate and Acegi caching

    I don't know if I'm writing in the correct column, but I want to set two different cache for acegi security and hibernate.

    I've tried to configure something like this:

    For acegi:
    Code:
    	<bean id="cacheManagerFactoryBean" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    		<property name="configLocation">
    			<value>classpath:ehcache.xml</value>
    		</property>
    	</bean>
    	
    	
    	<bean id="cacheFactoryBean" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
    		<property name="cacheManager">
    			<ref local="cacheManagerFactoryBean"/>
    		</property>
    		<property name="cacheName">
    			<value>usersCache</value>
    		</property>
    	</bean>
    	
    	
    	<bean id="usersCache" class="org.acegisecurity.providers.dao.cache.EhCacheBasedUserCache">
    		<property name="cache"><ref local="cacheFactoryBean" /></property>
    	</bean>
    	
    	
    	<bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">
    		<!-- <property name="authenticationDao">-->
    		<property name="userDetailsService">
    			<ref local="authenticationDao" />
    		</property>
    		 
    		<property name="userCache">
    			<ref local="usersCache"/>
    		</property>
    		
    	</bean>
    For hibernate:
    Code:
    <property name="hibernateProperties">
      <props>						
    				
        	        <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
        	        <prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache.xml</prop>
        	        <prop key="hibernate.cache.use_query_cache">true</prop>
        	        
      </props>
    </property>
    and my ehcache.xml:
    Code:
    <ehcache>
       <diskStore path="java.io.tmpdir"/>
    
       <defaultCache name="hibernateCache"
            maxElementsInMemory="100"
            eternal="false"
            timeToIdleSeconds="300"
            timeToLiveSeconds="300"
            overflowToDisk="true"
            />
            
             
        <cache name="usersCache"
            maxElementsInMemory="300"
            eternal="false"
            timeToIdleSeconds="500"
            timeToLiveSeconds="500"
            overflowToDisk="true"
            /> 
    </ehcache>
    I think that it doesn't work, so please give me some tips to configure it correctly.

    Solution with two different files for xml configuration also didn't work.

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Just out of interest what makes you think this isn't working?
    Last edited by karldmoore; Aug 29th, 2007 at 10:27 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #3
    Join Date
    Jun 2007
    Posts
    25

    Default

    Because in my log file I have only something like this

    for hibernate:
    Code:
    2007-07-09 16:14:09,873 DEBUG [org.hibernate.cache.EhCacheProvider] Creating EhCacheProvider from a specified resource: ehcache.xml Resolved to URL: file:/usr/share/JBoss/server/default/./deploy/bivela.war/WEB-INF/classes/ehcache.xml
    2007-07-09 16:14:09,901 DEBUG [net.sf.ehcache.config.ConfigurationFactory] Configuring ehcache from URL: file:/usr/share/JBoss/server/default/./deploy/bivela.war/WEB-INF/classes/ehcache.xml
    2007-07-09 16:14:09,901 DEBUG [net.sf.ehcache.config.ConfigurationFactory] Configuring ehcache from InputStream
    2007-07-09 16:14:09,917 DEBUG [net.sf.ehcache.config.DiskStoreConfiguration] Disk Store Path: /tmp
    2007-07-09 16:14:09,925 DEBUG [net.sf.ehcache.config.ConfigurationHelper] No CacheManagerEventListenerFactory class specified. Skipping...
    2007-07-09 16:14:09,926 DEBUG [net.sf.ehcache.config.ConfigurationHelper] No CachePeerListenerFactoryConfiguration specified. Not configuring a CacheManagerPeerListener.
    2007-07-09 16:14:09,926 DEBUG [net.sf.ehcache.config.ConfigurationHelper] No CachePeerProviderFactoryConfiguration specified. Not configuring a CacheManagerPeerProvider.
    2007-07-09 16:14:09,941 DEBUG [net.sf.ehcache.config.ConfigurationHelper] No BootstrapCacheLoaderFactory class specified. Skipping...
    and for acegi:
    Code:
    2007-07-09 16:14:11,223 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] Eagerly caching bean 'usersCache' to allow for resolving potential circular references
    2007-07-09 16:14:11,224 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] Creating shared instance of singleton bean 'cacheFactoryBean'
    2007-07-09 16:14:11,225 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] Creating instance of bean 'cacheFactoryBean' with merged definition [Root bean: class [org.springframework.cache.ehcache.EhCacheFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in ServletContext resource [/WEB-INF/acegi-security.xml]]
    2007-07-09 16:14:11,233 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] Eagerly caching bean 'cacheFactoryBean' to allow for resolving potential circular references
    2007-07-09 16:14:11,234 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] Creating shared instance of singleton bean 'cacheManagerFactoryBean'
    2007-07-09 16:14:11,234 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] Creating instance of bean 'cacheManagerFactoryBean' with merged definition [Root bean: class [org.springframework.cache.ehcache.EhCacheManagerFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in ServletContext resource [/WEB-INF/acegi-security.xml]]
    2007-07-09 16:14:11,242 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] Eagerly caching bean 'cacheManagerFactoryBean' to allow for resolving potential circular references
    2007-07-09 16:14:11,242 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] Invoking afterPropertiesSet() on bean with name 'cacheManagerFactoryBean'
    2007-07-09 16:14:11,242 INFO  [org.springframework.cache.ehcache.EhCacheManagerFactoryBean] Initializing EHCache CacheManager
    2007-07-09 16:14:11,242 DEBUG [net.sf.ehcache.config.ConfigurationFactory] Configuring ehcache from InputStream
    2007-07-09 16:14:11,244 DEBUG [net.sf.ehcache.config.DiskStoreConfiguration] Disk Store Path: /tmp
    2007-07-09 16:14:11,244 WARN  [net.sf.ehcache.CacheManager] Creating a new instance of CacheManager using the diskStorePath "/tmp" which is already used by an existing CacheManager.
    The source of the configuration was InputStream java.io.ByteArrayInputStream@29d838.
    The diskStore path for this CacheManager will be set to /tmp/ehcache_auto_created_1183990451244.
    To avoid this warning consider using the CacheManager factory methods to create a singleton CacheManager or specifying a separate ehcache configuration (ehcache.xml) for each CacheManager instance.
    2007-07-09 16:14:11,245 DEBUG [net.sf.ehcache.config.ConfigurationHelper] No CacheManagerEventListenerFactory class specified. Skipping...
    2007-07-09 16:14:11,245 DEBUG [net.sf.ehcache.config.ConfigurationHelper] No CachePeerListenerFactoryConfiguration specified. Not configuring a CacheManagerPeerListener.
    2007-07-09 16:14:11,245 DEBUG [net.sf.ehcache.config.ConfigurationHelper] No CachePeerProviderFactoryConfiguration specified. Not configuring a CacheManagerPeerProvider.
    2007-07-09 16:14:11,245 DEBUG [net.sf.ehcache.config.ConfigurationHelper] No BootstrapCacheLoaderFactory class specified. Skipping...
    2007-07-09 16:14:11,245 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] Invoking afterPropertiesSet() on bean with name 'cacheFactoryBean'
    2007-07-09 16:14:11,245 DEBUG [org.springframework.cache.ehcache.EhCacheFactoryBean] Creating new EHCache cache region 'hibernateCache'
    2007-07-09 16:14:11,245 DEBUG [net.sf.ehcache.store.DiskStore] Deleting data file hibernateCache.data
    2007-07-09 16:14:11,246 DEBUG [net.sf.ehcache.store.MemoryStore] Initialized net.sf.ehcache.store.LruMemoryStore for hibernateCache
    2007-07-09 16:14:11,246 DEBUG [net.sf.ehcache.store.LruMemoryStore] hibernateCache Cache: Using SpoolingLinkedHashMap implementation
    2007-07-09 16:14:11,246 DEBUG [net.sf.ehcache.Cache] Initialised cache: hibernateCache
    and there is no information at all that application uses objects from cache

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I've never tried this myself, but you appear to be loading the same ehcache.xml in both places. I would have thought you'd want to use two different files (one for each cache).
    Last edited by karldmoore; Aug 29th, 2007 at 10:27 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •