Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deregister empty Cache from CacheManager #33813

Closed
trung opened this issue Oct 29, 2024 · 4 comments
Closed

Deregister empty Cache from CacheManager #33813

trung opened this issue Oct 29, 2024 · 4 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@trung
Copy link

trung commented Oct 29, 2024

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?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 29, 2024
@jhoeller
Copy link
Contributor

jhoeller commented Oct 29, 2024

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

@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 29, 2024
@jhoeller jhoeller self-assigned this Oct 29, 2024
@jhoeller jhoeller modified the milestones: 6.2.0, 6.1.15 Oct 29, 2024
@trung
Copy link
Author

trung commented Oct 29, 2024

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

@ben-manes
Copy link
Contributor

ben-manes commented Oct 29, 2024

@jhoeller is instead @Bean @RequestScoped CacheManager the intended idiom?
(that was my best guess when asked in ben-manes/caffeine#1790)

@jhoeller
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants