javacachinginfinispancache-invalidation

Refresh expiration time of entry in Infinispan on get


I've been searching in the docs of infinispan but couldn't find out an easy way to refresh the expiration time of an entry after a get automatically.

Today I'm registering a Listener and, inside the @CacheEntryVisited event, I remove and put it inside again, but it is, of course, not ideal.

@CacheEntryVisited
public void entryVisited(CacheEntryVisitedEvent<String, String> event) {
    cache.remove(event.getKey);
    cache.put(event.getKey(), event.getValue(), 10, TimeUnit.SECONDS);
}

There is some kind of config that can be used in CacheManager to make this refresh?

thanks in advance


Solution

  • You can enable max idle expiration as described at [1]. Also the method you might be looking for is [2] which takes a lifespan and max idle expiration. You can pass -1 for a value which means to not use for expiration.

    Also you should be careful when using max idle in clustered caches as it is not guaranteed that other nodes will update their idle access times (if you read was local).

    [1] http://infinispan.org/docs/dev/user_guide/user_guide.html#expiration_details

    [2] https://docs.jboss.org/infinispan/9.2/apidocs/org/infinispan/commons/api/BasicCache.html#put-K-V-long-java.util.concurrent.TimeUnit-long-java.util.concurrent.TimeUnit-