Is it possible to get the current weight of a cache? #822
-
Hi, if I set up a cache with Caffeine.newBuilder()
.executor(context().dispatcher())
.maximumWeight(someWeightInBytes)
.weigher(new SomeWeigher())
.buildAsync((request, executor) -> load(request)); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes, you can use the policy api (wiki, javadoc) for these configuration-specific inspections. That is a bit hidden to not pollute the main api and keep it simpler, while also not blocking users by only offering an overly generic set of methods. Since it is a bit of a dumping ground those apis are less polished, so sorry if it could be a little nicer as it was added to as needed. var eviction = cache.policy().eviction().orElseThrow()
long currentWeight = eviction.weightedSize().orElseThrow() |
Beta Was this translation helpful? Give feedback.
Yes, you can use the policy api (wiki, javadoc) for these configuration-specific inspections. That is a bit hidden to not pollute the main api and keep it simpler, while also not blocking users by only offering an overly generic set of methods. Since it is a bit of a dumping ground those apis are less polished, so sorry if it could be a little nicer as it was added to as needed.