Limiting share of objects in the cache based on their type #788
Replies: 1 comment 3 replies
-
The cache's policy uses frequency and recency, so I don't know why else one might be preferred. If a weight is specified then a zero weight would not be size evicted and skipped over. Otherwise, currently the weight isn't used to make an eviction decision and the cache simply evicts until under the capacity threshold. Your idea might work but could also be error prone as hard to predict the resulting behavior. Potentially you could use variable expiration to expire negative lookups faster than positive ones. A refresh could hide the resulting latencies if actively used. You might consider logging an access trace to see actual production behavior which can differ from expectations. That could be a log message after a |
Beta Was this translation helpful? Give feedback.
-
Hi,
We use caffeine cache on top of a persistent database. In the caffeine cache we store (1) Positive lookups ie entries that do exist in the database (2) Negative lookups ie entries that don't exist. The value is simply a static object for the latter. The cache is created to store "maximumSize" entries - which i believe is the number of entries.
We notice that due to our usage pattern - entries of type (2) occupy 90%+ of the cache space (via a heap analysis).
I don't know why caffeine has a preference for them - our read traffic is much more balanced than that.
Is there a way we can limit the number of (2) entries in the cache relative to (1)?
I'm thinking of using "maximumWeight" to create the cache and associate a weight of 1 with (1) and let's say 10 with (2). Would this sort of an approach work? Please suggest other ideas
cc @ben-manes
Beta Was this translation helpful? Give feedback.
All reactions