Cache entry not surviving restart using SingleFileStore
jugglingcats Nov 29, 2013 3:34 PMHi, I'm new to Infinispan... I'm trying to reproduce the Groovy example in the getting started guide using the fluent API for configuration. I was led in this direction because I failed to get the Mongo store working and went for a more standard configuration/example to test things worked as I expected. I'm using 6.0.0 final.
The groovy example calls stop() and start() on the cache. If I follow this procedure, my key is retrieved from the cache ok, but if I stop the manager and recreate everything from scratch (to simulate an actual restart), it is not found.
Here is my unit test...
@Test
public void testValueAvailableAfterRestart() {
// given a file store configuration
Configuration configuration = new ConfigurationBuilder()
.persistence()
.passivation(false)
.addStore(SingleFileStoreConfigurationBuilder.class)
.fetchPersistentState(true)
.ignoreModifications(false)
.purgeOnStartup(false)
.preload(true)
.shared(false)
.build();
// and a cache manager with this configuration
EmbeddedCacheManager manager1=new DefaultCacheManager();
manager1.defineConfiguration("file-cache", configuration);
// and the cache defined therein
Cache<Object, Object> cache1 = manager1.getCache("file-cache");
// the cache doesn't contain my key
assertNull(cache1.get("key1"));
// but when the key is added
cache1.put("key1", "value1");
// the cache does contain my key
assertNotNull(cache1.get("key1"));
manager1.stop(); // avoid complaints about duplicate JMX bean
// given a fresh cache (simulating a restart)
EmbeddedCacheManager manager2=new DefaultCacheManager();
Cache<Object, Object> cache2=manager2.getCache("file-cache");
manager2.defineConfiguration("file-cache", configuration);
// it should contain my key (from the store)
assertNotNull(cache2.get("key1"));
}
Am I misunderstanding something fundamental here? Should entries in the SingleFileStore (and other cache stores) survive a restart? Is there something I need to force it to write (was expecting write-through by default)?
The eventual configuration I'm looking for is:
- Clustered cache backed by Mongodb
- Distributed mode to get some shared memory with resilience
- Long timeout on cache entries (eg. 3 months)
- Passivation based on cache size / available memory / time since last use
- Least used eviction strategy
- Custom Mongo store (because we have some reporting tools to run against mongo, so objects should be structured)
From what I read, this is a reasonable goal with Infinispan...?
Any advice appreciated.
Many thanks!
Alfie.