Fix memory leak in CaffeineCacheManager static mode by NYgomets · Pull Request #35821 · spring-projects/spring-framework

@NYgomets

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 <wngud5957@naver.com>

@sbrannen sbrannen added the in: core

Issues in core modules (aop, beans, core, context, expression)

label

Nov 15, 2025