Skip to content

Maximum cache size question #849

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

You must be logged in to vote

I understand that when adding an entry the weigher function is applied to calculate the entry size and added to the cache size counter, and when an entry is removed then the same function is invoked to substract that size. Does it work in this way?

The weigher is evaluated when the entry is created or updated, and stored with it. This way during removal we have it calculated and the math is guaranteed, else a new evaluation might give a different answer. That's also important in a case like weak/soft keys or values where the entry is GC'd, so we couldn't evaluate it after the fact. This means that if the entry's weight changes then the cache needs to be informed, e.g. a no-op asMap().re…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ben-manes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants