Reputation: 3557
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>
Upvotes: 0
Views: 686
Reputation: 326
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.
e.g.
@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.
Upvotes: 1