Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将infinispan缓存中的数据持久化到文件_Java_File_Caching_Persistence_Infinispan - Fatal编程技术网

Java 将infinispan缓存中的数据持久化到文件

Java 将infinispan缓存中的数据持久化到文件,java,file,caching,persistence,infinispan,Java,File,Caching,Persistence,Infinispan,我正在尝试将infinispan 6.0.2中的缓存数据持久化到文件中,我正在使用嵌入式模式,这是缓存配置: ConfigurationBuilder builder = new ConfigurationBuilder(); builder.eviction().strategy(EvictionStrategy.LRU).maxEntries(1) .persistence() .passivation(false) // save evicted entries t

我正在尝试将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();
//避免与org.infinispan已注册域相关的JMX问题
GlobalConfiguration globalConf=新的GlobalConfiguration Builder()
//.clusteredefault()
.globalJmxStatistics()
.MBeanServer查找(DummyMBeanServer.lookup)
.build();
EmbeddedCacheManager manager1=新的DefaultCacheManager(globalConf,配置);
manager1.start();
Cache cache1=manager1.getCache();//默认缓存
cache1.put(“key11”、“val11”);
cache1.put(“key12”、“val12”);
cache1.put(“key13”、“val13”);
缓存1.逐出(“键11”);//拼命想把这把钥匙搬到商店
cache1.stop();
//当我重新启动缓存时,所有数据都会丢失
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>


Pls。提供完整的代码。数据是如何编写的?事实上,我们需要看到您调用的代码和您已有的断言,正如cruftex所建议的那样。顺便说一句,删除singleton部分,因为它与这样的本地缓存不相关。由于禁用了钝化,每个put都将导致写入持久存储(即文件存储),因此不需要逐出调用。启动缓存时,如何验证数据是否丢失?你有没有试过为你储存的钥匙打电话?我看不出任何错误,因此最简单的方法是使用调试器并按照拦截器堆栈转到
CacheWriterInterceptor.visitPutKeyValueCommand()
。或者,在org.infinispan包上启用跟踪日志记录并查看一下。我故意禁用了钝化,以查看是否真的将某些内容保存到了存储中,然后我尝试了手动逐出,但什么也没有发生。我使用
cache1.get(“key11”)
读取条目!我还尝试了跟踪模式,但没有看到任何重要内容,然后从
PersistenceManagerImpl
在0毫秒内预装了0个键。我会和你建议的客人一起去试试。