Skip to content

Does caffeine can dynamicly adjustment cache size by JVM memory watermark? #564

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

You must be logged in to vote

The cache does not monitor available memory to adjust any setting. If you wish to do so, then it can be changed dynamically using the Cache.policy() api.

cache.policy().eviction().ifPresent(eviction -> {
  eviction.setMaximum(2 * eviction.getMaximum());
});

You can combine size-based eviction with soft references if you want a failsafe. This does add a small amount of per-entry memory overhead, though.

The cache's size eviction policy should be more GC friendly than a typical LRU, which violates the generational hypothesis (making it a GC benchmark for worst-case behavior). A SQL database is MRU / LFU biased, so the cache will auto-configure itself such that the admission policy will more…

Replies: 1 comment 10 replies

Comment options

You must be logged in to vote
10 replies
@krishna81m
Comment options

@ben-manes
Comment options

@guhanjie
Comment options

@adityamohan93
Comment options

@ben-manes
Comment options

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
4 participants