I use CaffeineCacheManager and create temporary caches dynamically for each request. When a request completes, the cache items are evicted, leaving the cache instances empty but still in memory.

CaffeineCacheManager has an internal cacheMap which keeps growing as caches are dynamically created.

Is there away to remove/deregister the empty cache instances from cacheMap?

Comment From: jhoeller

Good point, I'll add a removeCache(String name) method on CaffeineCacheManager for 6.1.15.

Comment From: trung

Please also add removeCache(String name) for ConcurrentMapCacheManager as well. I'm not using it but I do see it has similar need.

Comment From: ben-manes

@jhoeller is instead @Bean @RequestScoped CacheManager the intended idiom? (that was my best guess when asked in https://github.com/ben-manes/caffeine/discussions/1790)

Comment From: jhoeller

@ben-manes that would indeed work but I can also see the need for runtime removal of certain caches in a shared CacheManager scenario. As long as the cache names are distinct enough, I can see that working for short-lived request caches as well.