繁体   English   中英

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

[英]Infinispan not keep cache in file Wildfly 10

我正在使用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();
}

这是我的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>

解决方案:直接注入缓存。 这样可以确保在需要时安装缓存使用的缓存配置。 此外,WildFly将自动处理Cache及其依赖项的生命周期。

例如

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

我还建议直接使用UUID类型而不是字符串类型,因为它们会更有效地进行序列化。

暂无
暂无

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

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