Github user ben-manes commented on the issue:
https://github.com/apache/storm/pull/2218
fyi, you can emulate pinning by setting the entry's weight to zero. Then
the entry will not be evicted, but is eligible for expiration, etc. Of course
zero weight entries means the cache allows more entries overall, whereas
pinning might still restrict overall capacity. But its not clear how to a cache
should handle evictions when not enough space can be freed from unpinned
entries.
The other approach is less elegant. A `CacheWriter` can intercept an
eviction and a `CacheLoader` intercepts gets to fetch a missing entry. Since
recursive computations are disallowed, the writer could re-put the entry
asynchronously. This races with a `get`, so the loader could fetch from the map
prior to some other data store. In some ways not too dissimilar to your own
pinned cache.
In general pinning breaks the caching model of recomputable transient state
and the eviction policy will try to avoid pollution by removing low-value
entries early. Generally it can lead to O(n) evictions unless maintained in a
dedicated LRU queue so that potential victims are not evaluated. Since pinning
vs capacity is confusing, right now Caffeine favors zero weights since the
use-cases are unclear.
Hope that helps. I agree your own logic may be more straightforward and
preferable.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---