Maximum cache size question #849
-
Hi Ben, Imagine all entries are valid but the maximum cache size has been reached. Then an eviction process is triggered to remove "less used" entries. I understand you are using a kind of threshold to determine the number of entries to be removed. Is there any way to configure this threshold programatically? I would like my users to set up not only the cache size but also the % of entries to be removed in case of reaching the maximum cache size. And regarding the maximum weigth: 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? Thanks, Joan. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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
The most you can do is dynamically adjust the threshold via |
Beta Was this translation helpful? Give feedback.
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…