Fix memory leak in CaffeineCacheManager static mode#35821
Fix memory leak in CaffeineCacheManager static mode#35821NYgomets wants to merge 1 commit intospring-projects:6.2.xfrom
Conversation
b86be0c to
8e43a3f
Compare
When setCacheNames() is called to switch from dynamic to static mode, dynamically created caches were not removed from the internal cacheMap, causing: 1. Memory leak (orphaned cache references) 2. Violation of Javadoc contract stating cache names will be 'fixed' 3. getCacheNames() returning unexpected cache names This fix ensures that dynamically created caches are cleared when switching to static mode, while preserving custom caches registered via registerCustomCache(). Signed-off-by: ParkJuhyeong <[email protected]>
8e43a3f to
47706be
Compare
|
On review, For the specific case of "leaking" dynamic cache regions when a new set of fixed cache names is being configured, these formerly registered dynamic regions keep being accessible, so they are not really leaking. Also, if a specific set of cache names is set through Overall, I don't see us adding official clean-up semantics to Thanks for the PR, in any case! |
|
Thanks for the detailed explanation, Juergen. I understand the design philosophy regarding setCacheNames as a configuration-time method and the risk of implicit cleanup. Introducing an explicit resetCaches() method seems like a much safer and more flexible approach to handle runtime reconfiguration scenarios. I'm glad that my report contributed to improving the cache management capabilities. Thanks for addressing this! |
Description
This PR fixes a memory leak in
CaffeineCacheManagerwhere dynamically created caches were not removed when switching to static mode viasetCacheNames().Changes
Core Fix
CaffeineCacheManager.setCacheNames()to clear dynamically created caches while preserving custom cachesTests Added
setCacheNamesShouldRemovePreviousDynamicCaches(): Verifies dynamic caches are clearedsetCacheNamesShouldPreserveCustomCaches(): Ensures custom caches are not affectedswitchingBetweenDynamicAndStaticMode(): Tests mode transitionsBackward Compatibility
This is a potentially breaking change for users who rely on the (undocumented) behavior of dynamic caches persisting after
setCacheNames().However: