-
-
Notifications
You must be signed in to change notification settings - Fork 76
Description
Support of expiry after an entry is accessed is missing in core cache2k.
What is it?
An entry expires and is removed from the cache after being not accessed for a period of time. The main use is primarily for freeing resources and shrinking the cache when the application is not in use.
Current state:
The feature is available in the JCache support. However, it is not implemented very efficiently. Also, the standard functionality of JCache is not very practicable. JCache defines TTI, however it cannot be combined with expire after write.
Why it isn't available in cache2k, yet?
We almost never need it. Typically we run caches with a TTL between 30 seconds and 30 minutes. Which means that entries expire via the TTL setting and the cache shrinks. TTI would be needed if entries never expire via TTL or have a higher TTL than TTI. For example a web resource might be allowed to be cached for 6 days, however, if being not accessed we like to remove it from memory after one hour.
The second reason is the overhead. TTI is typically implemented via an LRU style linked list. This brings lock contention and concurrency issues.
Solutions
If needed several options are available via the existing cache2k features, e.g. the expiry can be modified in a cache request via the entry processor.
We also plan to do an efficient implementation of a TTI approximation which is based on the eviction algorithm.