Skip to content

Commit 022fdcd

Browse files
committed
Provide removeCache method on Caffeine/ConcurrentMapCacheManager
Closes gh-33813
1 parent 11ebcee commit 022fdcd

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

Diff for: spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCacheManager.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -303,6 +303,17 @@ public void registerCustomCache(String name, AsyncCache<Object, Object> cache) {
303303
this.cacheMap.put(name, adaptCaffeineCache(name, cache));
304304
}
305305

306+
/**
307+
* Remove the specified cache from this cache manager, applying to
308+
* custom caches as well as dynamically registered caches at runtime.
309+
* @param name the name of the cache
310+
* @since 6.1.15
311+
*/
312+
public void removeCache(String name) {
313+
this.customCacheNames.remove(name);
314+
this.cacheMap.remove(name);
315+
}
316+
306317
/**
307318
* Adapt the given new native Caffeine Cache instance to Spring's {@link Cache}
308319
* abstraction for the specified cache name.

Diff for: spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheManager.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -175,6 +175,15 @@ public Cache getCache(String name) {
175175
return cache;
176176
}
177177

178+
/**
179+
* Remove the specified cache from this cache manager.
180+
* @param name the name of the cache
181+
* @since 6.1.15
182+
*/
183+
public void removeCache(String name) {
184+
this.cacheMap.remove(name);
185+
}
186+
178187
private void recreateCaches() {
179188
for (Map.Entry<String, Cache> entry : this.cacheMap.entrySet()) {
180189
entry.setValue(createConcurrentMapCache(entry.getKey()));

0 commit comments

Comments
 (0)