1 of 1 people found this helpful
Have you tried if CacheEntryRemovedEvent works for your use case?
CacheEntryRemovedEvent is meant for explicit removal only, not for removal due to expiration.
What we ultimately did was to create our own expiration logic and then use Infinispan's cache entry removed event to distribute the message to local and remote nodes.
I still find it a bit odd that expire events are not supported, given the fact that remove events are.
Ah yes, I forgot. The jira issue that you linked explains some of the caveats of implementing this, particularly when the expired elements are not in memory but in the cache store.
The other slight problem is that a lot of the logic to check for expired elements is within the inner data container, where we can remove entries directly without emitting any notifications.
Btw, out of curiosity, what kind of things do you do when the entry is expired?
The system in question acts as an enterprise JSON web service for Single Sign-On (SSO), shared session management and OpenID Connect IdP/IdC.
Expiration events are primarily used with sessions:
- Send web events to listenening apps that a user's session has expired.
- Release shared session data objects.
- Release optional LDAP connection bound as the user during the session.
- Register event with the session logger.
- Update various user stats.
We spent about three months evaluating Ehcache/Terracotta and Infinispan, and in the end decided to settle for the latter, despite the lack of Infinispan expiration events. These we reproduced by creating our own expiration logic on top of Infinispan.
The whole experience is worth writing a book
I dunno the JBoss Application Server code by hard, but this is the kind of stuff the clustering integration code needs to deal with, so I'd suggest you dig a little into https://github.com/jbossas/jboss-as/tree/master/clustering to see what's done when web sessions expire and how they deal with capturing these events. I suspect that, as if you're already doing, they might have an external service, within the web container, that tells them when a session has expired, and so end up with a similar solution to yours.
I'd love to read that book