簡體   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