Search code examples
cachinginfinispandistributed-caching

Update Infinispan objects maintaining expiration time


I'm using an instance of org.infinispan.Cache (Infinispan API) so it's very easy to put, remove, find objects.

The object I put has a fixed lifespan. For example, I put an object with a lifespan of 5 minutes. During the lifetime of this object, I want to modify some attributes but I want to maintain the original lifespan. For example, after 2 minutes I update the object. I want my object to expire is 3 minutos after update.

I think a simple way is getting the object, calculating the remaining lifespan and calling replace() method on the cache API with the remaining lifespan. But this method is a little tricky.

I reviewed org.infinispan.Cache API and I couldn't find a simple way to update/replace the object and maintain the original lifespan. All methods receive lifespan as arguments.

Is there a simple way to update infinispan objects maintaining the original lifespan?

Thank you very much!


Solution

  • The only other option is to modify your objects directly. That will work if your cache is not clustered and you are neither using a cache store nor enabling store-as-binary.

    However, it would require your objects to be synchronized, and it destroys transaction isolation. So I would recommend keeping your current approach.