2

I am currently migrating from ConcurrentLinkedHashMap to Caffeine and I am stuck on trying to find an equivalent feature of setCapacity

  _myCache.setCapacity(newCacheSize);

Is there a way to do the same in Caffeine ?

Should I copy my current cache into a newly created one with the new size ? That doesn't seem very efficient but I don't see another way to do so at the moment

Frederic
  • 2,015
  • 4
  • 20
  • 37

1 Answers1

3

These knobs are tucked away under cache.policy() as they are specific to how the cache was created. This way many messy methods can be provided without complicating the core apis.

cache.policy().eviction().ifPresent(eviction -> {
  eviction.setMaximum(newCacheSize);
});
Ben Manes
  • 9,178
  • 3
  • 35
  • 39