0

I am using Caffeine as cache manager in my project. How can I set maximum memory usage (for example 1GiB)?

Wiktor
  • 71
  • 1
  • 9
  • Have you seen the documentation? https://github.com/ben-manes/caffeine/wiki/Eviction#size-based – Marvin Jul 27 '22 at 13:56
  • 1
    @Marvin yes, but it turns out that `maximumSize` is "maximum number of entries the cache may contain" and `maximumWeight` is essentially the same, but sizes are weighted. Therefore, it doesn't solve my problem. – Wiktor Jul 27 '22 at 14:18
  • 1
    You can measure the entry's memory usage and return that as its weight. For example using [JAMM](https://github.com/jbellis/jamm). This is inexact science (see [JEP 8249196](https://openjdk.org/jeps/8249196)), so a weigher gives you the flexibility to estimate it without Caffeine stepping into this murky topic. – Ben Manes Jul 27 '22 at 16:56

0 Answers0