简体   繁体   中英

Infinispan not keep cache in file Wildfly 10

I'm using Infinispan, but when restart my Wildfly not keep the cache in file store

@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

<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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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