简体   繁体   English

将infinispan缓存中的数据保存到文件中

[英]Persisting data in infinispan cache to file

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: 我正在尝试将infinispan 6.0.2中的缓存数据保存到文件中,我正在使用嵌入模式,这是缓存配置:

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 (ie no update). 它对我不起作用(我没有错误),文件存储在文件系统中创建但只包含“FCS1”,如果它已经创建,则没有任何事情发生(即没有更新)。 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();

When using the following XML configuration (which is almost the same as the above!) I can find my entries in the store: 使用以下XML配置时(几乎与上面的相同!)我可以在商店中找到我的条目:

<?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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM