-
|
Hi, I’m implementing a delegating cache using Caffeine Cache and the Spring Cache abstraction. Previously, I used CaffeineCache’s expireAfterWrite and set the TTL for the delegated cache via FixedExpiration#getExpiresAfter. To minimize negative caching, I changed the behavior so that when a null value is cached, a shorter TTL is applied using expireAfter. However, after this change, when configuring the delegating cache I can no longer read the TTL that’s set in the Caffeine cache. With expireAfter, it seems that VarExpiration#getExpiresAfter is only available if the entry is already present in the cache. Is there any way to query the TTL configured via expireAfter even when no entry exists yet? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The fixed expiration like |
Beta Was this translation helpful? Give feedback.
The fixed expiration like
expireAfterWritemeans there is a duration the cache knows about and schedules with. The variable expiration likeexpireAfter(Expiry)means that there is logic that the cache calls with the key/value to determine the schedule. That is logic, e.g.Expiry.writing((key, value) -> (key % 1 == 0) ? Duration.ofMinutes(1) : Duration.ofMinutes(5)). There isn't a way to know for an absent entry, and since its your logic then you can call that if reasonable. I'm not sure about the Spring side which might make that harder.