I’m using a guava LoadingCache with eviction policy set expireAfterWrite(). I also invalidate entries on access using:
v = cache.getIfPresent( k );
if( v != null ) {
cache.invalidate( k );
}
Is there a way to add a RemovalListener that gets fired only when entries get auto-evicted after the write timeout is hit? From documentation, it appears that the RemovalListener is called any time an entry is removed.
Yes, a
RemovalListenerwill be called any time any entry is removed — but theRemovalListenerwill receive aRemovalNotificationobject, which includes the cause, which you can use to determine how an entry got removed.