1 Reply Latest reply on Jun 8, 2007 6:32 AM by manik

    EvictionPolicyConfig and CacheLoaderConfiguration

    sioux

      Hi,
      I've been looking at eviction policies and have found that my CacheLoaderConfiguration config entry breaks my eviction policy.
      e.g. this unit test (taken roughly from jboss src) -

      public void testInUseEviction() throws Exception
       {
       long wakeupIntervalMillis_ = 3000;
       String rootStr = "/org/jboss/test/data/inuse/";
       Fqn fqn;
       for (int i = 0; i < 10; i++)
       {
       String str = rootStr + i;
       fqn = Fqn.fromString(str);
       tree.put(fqn, str, str);
       }
      
       Thread.sleep(wakeupIntervalMillis_ + 500);
       tree.getEvictionRegionManager().markNodeCurrentlyInUse(Fqn.fromString(rootStr + 5), 0);
      
       for (int i = 10; i < 15; i++)
       {
       String str = rootStr + i;
       fqn = Fqn.fromString(str);
       tree.put(fqn, str, str);
       }
      
       Thread.sleep(wakeupIntervalMillis_ + 500);
      
       for (int i = 0; i < 5; i++)
       {
      //fails here
       assertNull(tree.get(Fqn.fromString(rootStr + i)));
       }
      }

      works with this config:
      <server>
      
       <classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar" />
       <!-- ==================================================================== -->
       <!-- Defines TreeCache configuration -->
       <!-- ==================================================================== -->
      
       <mbean code="org.jboss.cache.TreeCache" name="jboss.cache:service=TreeCache">
       <attribute name="CacheMode">LOCAL</attribute>
      
      
       <attribute name="EvictionPolicyClass">org.jboss.cache.eviction.LRUPolicy</attribute>
      
       <attribute name="EvictionPolicyConfig">
       <config>
       <attribute name="wakeUpIntervalSeconds">5</attribute>
       <region name="/_default_">
       <attribute name="maxNodes">5000</attribute>
       <attribute name="timeToLiveSeconds">1000</attribute>
       </region>
       <region name="/org/jboss/data">
       <attribute name="maxNodes">5000</attribute>
       <attribute name="timeToLiveSeconds">1000</attribute>
       </region>
       <region name="/org/jboss/test/data">
       <attribute name="maxNodes">5</attribute>
       <attribute name="timeToLiveSeconds">4</attribute>
       </region>
       </config>
       </attribute>
      
      
       </mbean>
      </server>


      but not when I include this section:
      <attribute name="CacheLoaderConfiguration">
       <config>
       <passivation>false</passivation>
       <preload>/</preload>
       <shared>false</shared>
       <cacheloader>
       <class>org.jboss.cache.loader.FileCacheLoader</class>
      
       <properties>location=/tmp/testcachestore</properties>
      
       <async>false</async>
       <fetchPersistentState>true</fetchPersistentState>
       <ignoreModifications>false</ignoreModifications>
       <purgeOnStartup>true</purgeOnStartup>
       </cacheloader>
      
       </config>
       </attribute>


      Is there a way for me to use both features on a single cache? (My goal is to back up the cache to a file store but also to replace all data items over a 24 hour period for which I was considering a custom eviction policy or lazy loading following eviction).
      Thanks for any suggestions or help understanding this.
      Sioux

        • 1. Re: EvictionPolicyConfig and CacheLoaderConfiguration
          manik

          Your test is flawed. When something is evicted from memory, it no longer exists in memory but still exists in the cache loader. So when you do a cache.get() the cache sees that the data is not in memory and then proceeds to check if it is in the cache loader (which it is) and then loads data from there.

          Change the test to check cache.exists() rather than cache.get(). cache.exists will bypass cache loaders.