0

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>
Mise
  • 3,267
  • 1
  • 22
  • 22
  • Can't say of the top of my head, but you shouldn't need to start the manager since it's already started when injected. Can you try removing that? – Galder Zamarreño Aug 22 '16 at 08:24

1 Answers1

1

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.

Paul Ferraro
  • 326
  • 1
  • 3