繁体   English   中英

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

[英]Persisting data in infinispan cache to file

我正在尝试将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();

它对我不起作用(我没有错误),文件存储在文件系统中创建但只包含“FCS1”,如果它已经创建,则没有任何事情发生(即没有更新)。 以下是将键/值对添加到缓存的代码(没什么特别之处):

// 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();

使用以下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