[jboss-user] [JBoss Cache] - CacheLoader store not recreating keys/values

jaysmith do-not-reply at jboss.com
Tue Apr 12 04:27:17 EDT 2011

jaysmith [http://community.jboss.org/people/jaysmith] created the discussion

"CacheLoader store not recreating keys/values"

To view the discussion, visit: http://community.jboss.org/message/599443#599443

Hi there,

I have a simple proof of concept JUnit that creates a cache, creates a node, creates a test object and adds this object to the node.  The cache is configured with a FileCacheLoader, passivation disabled and eviction happens after 2 seconds.
What I would expect to see is that when the object is added to the node, both RAM and disk are written to, after 2 seconds then memory should be cleared. After that time, a read should load the node and the object that the node contains back into memory.
However, what I'm actually seeing is different. After 2 seconds has elapsed and the node has been evicted from RAM, a read recreates the node from the persistent store but it is empty i.e. the object that the node orginally stored is no longer there.

My configuration:
<?xml version="1.0" encoding="UTF-8"?>
<jbosscache xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:jboss:jbosscache-core:config:3.2">

      isolation levels supported: READ_COMMITTED and REPEATABLE_READ
      nodeLockingSchemes: mvcc, pessimistic (deprecated), optimistic (deprecated)
      Used to register a transaction manager and participate in ongoing transactions.
      Used to register JMX statistics in any available MBean server
   <jmxStatistics enabled="false"/>
      If region based marshalling is used, defines whether new regions are inactive on startup.
   <startup regionsInactiveOnStartup="true"/>
      Used to register JVM shutdown hooks.
   <shutdown hookBehavior="DEFAULT"/>
      Used to define async listener notification thread pool size
   <listeners asyncPoolSize="1" asyncQueueSize="100000"/>
      Used to enable invocation batching and allow the use of Cache.startBatch()/endBatch() methods.
   <invocationBatching enabled="false"/>
      serialization related configuration, used for replication and cache loading
   <serialization objectInputStreamPoolSize="12" objectOutputStreamPoolSize="14" version="3.0.0"
         marshallerClass="org.jboss.cache.marshall.VersionAwareMarshaller" useLazyDeserialization="false"
      Eviction configuration.  WakeupInterval defines how often the eviction thread runs, in milliseconds.  0 means
      the eviction thread will never run.
   <eviction wakeUpInterval="500">
      <default algorithmClass="org.jboss.cache.eviction.LRUAlgorithm" eventQueueSize="200000">
         <property name="maxNodes" value="5000" />
         <property name="timeToLive" value="1000" />
      <region name="/griffin_peter">
         <property name="timeToLive" value="2000" />
         <!--<property name="maxAge" value="10000" />-->
      <region name="/org/jboss/data2" algorithmClass="org.jboss.cache.eviction.FIFOAlgorithm" eventQueueSize="100000">
         <property name="maxNodes" value="3000" />
         <property name="minTimeToLive" value="4000" />
      Cache loaders.
      If passivation is enabled, state is offloaded to the cache loaders ONLY when evicted.  Similarly, when the state
      is accessed again, it is removed from the cache loader and loaded into memory.
      Otherwise, state is always maintained in the cache loader as well as in memory.
      Set 'shared' to true if all instances in the cluster use the same cache loader instance, e.g., are talking to the
      same database.
   <loaders passivation="false" shared="false">
         <node fqn="/griffin_peter"/>
      <loader class="org.jboss.cache.loader.FileCacheLoader" async="true" fetchPersistentState="true"
              ignoreModifications="false" purgeOnStartup="true">
         <singletonStore enabled="false" class="org.jboss.cache.loader.SingletonStoreCacheLoader">

Here is the code I have (based on code in JBoss Cache User Guide 3.x.x)

package tests.cache.loader;

import org.jboss.cache.Cache;
import org.jboss.cache.CacheFactory;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class CustomCacheLoaderTest {
    /** cache. */
    private static Cache<String, Object> cache = null;
    class TestTO {
        private String field1;
        public String toString() {
            return this.getClass().getSimpleName() + ": field1=" + field1;
    public final static void afterClass() throws Exception {
        cache = null;
    public final static void beforeClass() throws Exception {
        CacheFactory cacheFactory = new DefaultCacheFactory();
        cache = cacheFactory.createCache("jboss-cache-configuration.xml");
    public final void put() throws Exception {
        Object listener = new CustomCacheListener();
        Node rootNode = cache.getRoot();
        Fqn peterGriffinFqn = Fqn.fromString("/griffin_peter");
        Node peterGriffinNode = rootNode.addChild(peterGriffinFqn);

        TestTO testTO = new TestTO();
        testTO.field1 = "This is a test string!";
        peterGriffinNode.put("testTO", testTO);
        System.out.println("Fqn: /griffin_peter: Key=testTO; Value="
                + cache.get("/griffin_peter", "testTO"));

        System.out.println("\nWaiting for 4000 milliseconds ...");
        java.util.Map data = cache.getData(Fqn.fromString("/griffin_peter"));
        System.out.println("data.size()=" + data.size());
        System.out.println("Fqn: /griffin_peter: Key=testTO; Value="
                + cache.get("/griffin_peter", "testTO"));

this outputs:
Fqn: /griffin_peter: Key=testTO; Value=TestTO: field1=This is a test string!

Waiting for 4000 milliseconds ...

Fqn: /griffin_peter: Key=testTO; Value=null

When I plug a Cache Listener in, the output is:
09:04:07.678 [CustomCacheListener] Created node: /griffin_peter09:04:07.803 [CustomCacheListener] Created node: /griffin_peter
09:04:07.819 [CustomCacheListener] Visited node: /griffin_peter
09:04:07.819 [CustomCacheListener] Visited node: /griffin_peter
Fqn: /griffin_peter: Key=testTO; Value=TestTO: field1=This is a test string!

Waiting for 4000 milliseconds ...
09:04:09.866 [CustomCacheListener] Evicted node: /griffin_peter
09:04:09.866 [CustomCacheListener] Evicted node: /griffin_peter
09:04:11.819 [CustomCacheListener] Created node: /griffin_peter
09:04:11.819 [CustomCacheListener] Created node: /griffin_peter
09:04:11.819 [CustomCacheListener] Visited node: /griffin_peter
09:04:11.819 [CustomCacheListener] Visited node: /griffin_peter
Fqn: /griffin_peter: Key=testTO; Value=null

So, the RAM is evicted at 09:04:09.866, node is recreated from backend store at 09:04:11.819 but the value for key testTO is null when it should be a TestTO object with field1 populated.

Any ideas why the backend store isn't storing keys and values?

Reply to this message by going to Community

Start a new discussion in JBoss Cache at Community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110412/411914c5/attachment-0001.html 

More information about the jboss-user mailing list