Question

I want to process cache entries before they expire, this is my use case:

I am using a Cache<ClientID,DataForClient> (with 10mins expiration and no cache-store) to put data in my app server, so remote clients can retrieve this data from the app server before the data expire.

Before the data in the cache expire I want to warn the few lazy remote clients who haven't retrieved their data, so they can hurry up and retrieve their data before it gets expired.

How can I achieve this?


  • Reducing the expiration time and adding a Listener on CacheEntryRemovedEvent to re-add the removed elements is not correct: The client could try to get its data while the listener is re-adding it, removing and re-adding simply doesn't look good, and implementing logic to re-add only once would make this more complicated.

  • Assuming that it is possible to get the cache entries (the keys would suffice) in expiration order (for example the ones which are close to its expiration time are at the beginning ) without modifying its last_accessed_time (so this wouldn't interfere with the cache mechanisms to clean up expired entries), I would send warnings to the lazy clients to hurry up and come for their data.

  • I thought about enabling passivation, processing passivated and activated events, and configuring a data store but.... it would over complicate the solution.

Was it helpful?

Solution

You can create another cache Cache<ClientID, Void> where the entries will have shorter lifespan. Then, you can use the listener on CacheEntryRemovedEvent to notify the client. You can even automate creation of this record via another listener for CacheEntryCreatedEvent/CacheEntryModifiedEvent.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top