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