Question

I'm trying to persist cached data from infinispan 6.0.2 to a file, I'm using the embedded mode and this is the cache configuration:

ConfigurationBuilder builder = new ConfigurationBuilder();
builder.eviction().strategy(EvictionStrategy.LRU).maxEntries(1)
      .persistence()
      .passivation(false) // save evicted entries to cache store
      .addSingleFileStore()
         .preload(true)
         .shared(false)
         .fetchPersistentState(true)
         .ignoreModifications(false)
         .purgeOnStartup(false)
         .location(System.getProperty("java.io.tmpdir")+"infinispan")
         //.async().enabled(true).threadPoolSize(5)
         .singleton()
            .enabled(true)
            .pushStateWhenCoordinator(true)
            .pushStateTimeout(20000);
Configuration configuration = builder.build();

It does not work for me (and I don't have errors), the file store is created in the file system but contains only "FCS1" and if it's already created nothing happen (i.e. no update). Here is the code (nothing fancy) for adding key/value pairs to the cache:

// Avoid JMX problems related to org.infinispan already registered domain
GlobalConfiguration globalConf = new GlobalConfigurationBuilder()
                                        //.clusteredDefault()
                                        .globalJmxStatistics()
                                        .mBeanServerLookup(DummyMBeanServer.lookup)
                                        .build();
EmbeddedCacheManager manager1 = new DefaultCacheManager(globalConf, configuration);
manager1.start();
Cache<String, String> cache1 = manager1.getCache(); // default cache
cache1.put("key11", "val11");
cache1.put("key12", "val12");
cache1.put("key13", "val13");
cache1.evict("key11"); // a desperate attempt to move this key to the store
cache1.stop();
// when I restart the cache all data is lost
cache1.start();
Was it helpful?

Solution

When using the following XML configuration (which is almost the same as the above!) I can find my entries in the store:

<?xml version="1.0" encoding="UTF-8"?>
<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="urn:infinispan:config:6.0 http://www.infinispan.org/schemas/infinispan-config-6.0.xsd"
  >

<!-- Using the cluster mode with grouping API-->

<global>
    <globalJmxStatistics enabled="false" />
</global>

<default>
    <!-- Enbaling eviction/expiration -->
    <eviction strategy="LRU" maxEntries="2000" />
    <expiration lifespan="1000" maxIdle="500" />
    <jmxStatistics enabled="false" />

    <clustering>
        <hash>
            <groups enabled="true" />
        </hash>
    </clustering>       
</default>

<namedCache name="CacheStore">
    <persistence passivation="false">
        <singleFile fetchPersistentState="true"
            ignoreModifications="false"
            purgeOnStartup="false" location="${java.io.tmpdir}">
            <async
                enabled="true"
                flushLockTimeout="15000"
                threadPoolSize="5" />
        </singleFile>
    </persistence>
</namedCache>

</infinispan>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top