0 Replies Latest reply on Feb 24, 2009 12:40 PM by Rob Beer

    EJB3.0 Cache eviction policy not firing

    Rob Beer Newbie

      Config:

      Java version "1.6.0_02"
      JBoss 4.2.2.GA which ships with:
      - JBoss Cache 1.4.1.SP5
      - Hibernate EntityManager 3.2.1.GA
      - Hibernate Annotations 3.2.1.GA
      - Hibernate 3.2.4.sp1

      Overview:

      I'm quite new to JBoss caching and have been able to place queries into the cache. For reasons beyond me, the eviction policy I have defined for my cache region is not firing and therefore the object is not removed from memory after the timeToLiveSeconds value has passed. To add to this, periodically every node within the cache is removed by org.jboss.cache.eviction.BaseEvictionAlgorithm.

      I believe that I have setup the cache eviction policies correctly within all/deploy/ejb3-entity-cache-service.xml as follows:

      <attribute name="InitialStateRetrievalTimeout">17500</attribute>
       <attribute name="SyncReplTimeout">17500</attribute>
       <attribute name="LockAcquisitionTimeout">15000</attribute>
       <attribute name="EvictionPolicyConfig">
       <config>
       <attribute name="wakeUpIntervalSeconds">1</attribute>
      
       <!-- Cache wide default -->
       <region name="/_default_" policyClass="org.jboss.cache.eviction.LRUPolicy">
       <attribute name="maxNodes">5000</attribute>
       <!-- small number for testing only -->
       <attribute name="timeToLiveSeconds">10</attribute>
       </region>
       <!-- Query region -->
       <region name="/myprefix/Queries" policyClass="org.jboss.cache.eviction.LRUPolicy">
       <attribute name="maxNodes">50</attribute>
       <!-- small number for testing only -->
       <attribute name="timeToLiveSeconds">5</attribute>
       </region>
       </config>
       </attribute>


      I have enabled query caching by defining the following in persistence.xml:

       <properties>
       <property name="hibernate.cache.use_query_cache" value="true"/>
       <property name="hibernate.cache.use_second_level_cache" value="true"/>
       <property name="hibernate.cache.region_prefix" value="myprefix"/>
       <property name="hibernate.cache.provider_class" value="org.jboss.ejb3.entity.TreeCacheProviderHook" />
       <property name="hibernate.treecache.mbean.object_name" value="jboss.cache:service=EJB3EntityTreeCache" />
       </properties>
      
      
      

      I can see the query nodes within the TreeCache by enabling and running the following:

      <mbean code="org.jboss.cache.TreeCacheView" name="jboss.cache:service=TreeCacheViewEJB3EntityTreeCache">
       <depends>jboss.cache:service=EJB3EntityTreeCache</depends>
       <attribute name="CacheService">jboss.cache:service=EJB3EntityTreeCache</attribute>
      </mbean>


      Below is the named query with caching enabled:
      @NamedQuery(name = "Venue.findById", query = "SELECT v FROM Venue v WHERE v.venueId = :id", hints=
      {@QueryHint(name="org.hibernate.cacheable",value="true"),
      @QueryHint(name="org.hibernate.cacheRegion", value="Queries")})


      These two lines worry me (any idea why config: null appears?):
      [org.jboss.system.ServiceConfigurator] EvictionPolicyConfig set to [config: null] in jboss.cache:service=EJB3EntityTreeCache
      [org.jboss.cache.TreeCache] setEvictionPolicyConfig(): [config: null]


      I can see that the region is created and the eviction timer is started:

      [org.jboss.cache.eviction.LRUConfiguration] parseConfig: name -- /myprefix/Queries maxNodes -- 50 timeToLiveSeconds -- 5 maxAgeSe
      onds -- 0
      [org.jboss.cache.eviction.RegionManager] createRegion(): creating region for fqn- /myprefix/Queries
      [org.jboss.cache.eviction.RegionManager] Starting eviction timer
      [org.jboss.cache.TreeCache] Started jboss.cache:service=EJB3EntityTreeCache


      I can see the the query being cached but under a different fqn as I defined (and a different cache maybe??):

      [org.hibernate.cache.StandardQueryCache] caching query results in region: myprefix./Queries; timestamp=12354921739


      This line appears periodically and removes everything from the cache:

      [org.jboss.cache.eviction.BaseEvictionAlgorithm] Visiting node that was not added to eviction queues. Assuming that it has 1 element


      Any help with this issue would be greatly appricated.

      Rob.