Skip to content

Cache and refence counting #820

Answered by ben-manes
AndreiSolodinTR asked this question in Q&A
Discussion options

You must be logged in to vote

The cache is best viewed as a bounded ConcurrentMap, so like HashMap your own logic would act as a facade above it rather than being the direct client api. If you simply need to increment a per-entry counter on access then that is trivial to do in your code and the library offering something doesn't add much value.

The faq discusses a similar problem called pinning, where ref counted entries should not be evictable. To do that the counter can be modified within a Map computation, so that when the cache evaluates its expiration and weight those can be set to be disabled. You might find that useful or else a similar approach if you want the increment to be atomic with the entry (but as a ca…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
4 replies
@AndreiSolodinTR
Comment options

@ben-manes
Comment options

@AndreiSolodinTR
Comment options

@ben-manes
Comment options

Answer selected by ben-manes
Comment options

You must be logged in to vote
1 reply
@ben-manes
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants