- Spring (.. @Cacheable, @CacheEvict ..) 1 . @CacheEvict ( allEntries, ), () .
Spring Cache, evict (key: Object) . (, GemfireCache), , , (, , GemFire, Google Guava Cache, . .)
, . - .
, , , , ... , . , @CacheEvict "", , . , - SpEL ...
@CacheEvict(condition = "#key.startsWith('abc')")
public void someMethod(String key) {
...
}
. , , . , ...
@CacheEvict
public void someMethod(String keyPattern) {
...
}
, Guava , "" , GuavaCache.
public class CustomGuavaCache extends org.springframework.cache.guava.GuavaCache {
protected boolean isMatch(String key, String pattern) {
...
}
protected boolean isPattern(String key) {
...
}
@Override
public void evict(Object key) {
if (key instanceof String && isPattern(key.toString()))) {
Map<String, Object> entries = this.cache.asMap();
Set<String> matchingKeys = new HashSet<>(entries.size());
for (String actualKey : entries.keySet()) {
if (isMatch(actualKey, key.toString()) {
matchingKeys.add(actualKey);
}
}
this.cache.invalidateAll(matchingKeys);
}
else {
this.cache.invalidate(key);
}
}
}
GuavaCacheManager, "" GuavaCache (CustomGuavaCache)...
public class CustomGuavaCacheManager extends org.springframework.cache.guava.GuavaCacheManager {
@Override
protected Cache createGuavaCache(String name) {
return new CustomGuavaCache(name, createNativeGuavaCache(name), isAllowNullValues());
}
}
Guava invalidateAll (: ). , , Java Regex "" , isMatch(key, pattern).
, , ( - ) () , ( ; -)
, !
Cheers,