-
|
I have a use-case where I want to track which keys have already been computed recently. The number of keys will be huge so I want some time-based eviction policy. Caffeine fits the bill, except there is no corresponding value to be cached for each key. I can of course build a cache with a dummy object for values but I was wondering if there exists a more efficient way to do this? Does getting an instance of |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
All of Java's |
Beta Was this translation helpful? Give feedback.
All of Java's
Setimplementations use a dummy value with a Map, whereBoolean.TRUEis idiomatic. TheCache.policy()can provide a best effort ordered view, such as by hot/cold or young/old. However, this is mostly for cases like persisting for a warm restart so it is meant for infrequent usage as it requires obtaining the eviction lock, meaning excessively long hold times could impact eviction. Also since it is a concurrent data structure, we are less concerned about exactness as caching is fundamentally a probabilistic problem. If you need something more precise then you might maintain a secondary data structure that is written into by your compute.