简体   繁体   English

Infinispan不在文件Wildfly 10中保留缓存

[英]Infinispan not keep cache in file Wildfly 10

I'm using Infinispan, but when restart my Wildfly not keep the cache in file store 我正在使用Infinispan,但是重新启动Wildfly时不会将缓存保留在文件存储中

@Resource(lookup = "java:jboss/infinispan/container/server")
private EmbeddedCacheManager manager;

public String test() {
this.cache.put(UUID.randomUUID().toString(), new Date());
    this.cache.put(UUID.randomUUID().toString(), new Date());
    this.cache.put(UUID.randomUUID().toString(), new Date());
    this.cache.put(UUID.randomUUID().toString(), new Date());
    this.cache.put(UUID.randomUUID().toString(), new Date());
}

@PostConstruct
protected void init() {
    this.manager.start();
    this.cache = this.manager.getCache();
}

This is my standalone.xml 这是我的standalone.xml

<cache-container name="server" default-cache="default" module="org.wildfly.clustering.web.infinispan">
    <local-cache name="default">
        <transaction mode="BATCH"/>
        <file-store relative-to="jboss.server.data.dir" path="infinispan" passivation="false" purge="false"/>
    </local-cache>
</cache-container>

The solution: Inject your cache directly. 解决方案:直接注入缓存。 This ensures that the cache configuration used by your cache is installed when you need it. 这样可以确保在需要时安装缓存使用的缓存配置。 Additionally, WildFly will automatically handle the lifecycle of the Cache and its dependencies. 此外,WildFly将自动处理Cache及其依赖项的生命周期。

eg 例如

@Resource(lookup = "java:jboss/infinispan/cache/server/default")
private Cache<UUID, Date> cache;

I'd also recommend using UUID types directly, rather than a String, as these will serialize more efficiently. 我还建议直接使用UUID类型而不是字符串类型,因为它们会更有效地进行序列化。

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

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