expireAfterRead question #838
-
Hi Ben, In our removalListener, how can I know if an expired entry comes from an 'expireAfterCreate' or an 'expireAfterRead? is the RemovalCause different? Another thing I'm probably doing wrong. This is my Expiry:
The removalListener is not using the 'expireAfterRead'. For example, I have a cache with a 1 minute cache time and 30 seconds of max idle time. When I insert an entry, I see the 'expireAfterCreate' trace, and after 1 minute I see the 'removalListener' trace, but I should see this trace after 30 seconds because there were no reads/writes on this period, so the max idle time should have been triggered. Thanks, Joan. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi Joan, The expiration policy maintains a single per-entry timestamp so that each operation mutates this lifetime value. In your test case there were no reads, so it did not reset the timestamp to cause it to evict earlier. The This generally gives the desired behavior and helps us minimize the memory overhead. If you wanted distinct policies like you described, then you could retain the multiple fields on the value yourself and return the minimum duration. Similarly if you wanted to indicate what dominant expiration was in play to indicate within the removal listener what caused the expiration event. It is a little bit more code and usually not helpful other than for gaining api familiarity. |
Beta Was this translation helpful? Give feedback.
Hi Joan,
The expiration policy maintains a single per-entry timestamp so that each operation mutates this lifetime value. In your test case there were no reads, so it did not reset the timestamp to cause it to evict earlier. The
currentDuration
is passed in to allow a method to return that to indicate no changes.This generally gives the desired behavior and helps us minimize the memory overhead. If you wanted distinct policies like you described, then you could retain the multiple fields on the value yourself and return the minimum duration. Similarly if you wanted to indicate what dominant expiration was in play to indicate within the removal listener what caused the expiration event. I…