@spring缓存中的缓存

@spring缓存中的缓存,spring,caching,Spring,Caching,我在页面列表中使用了缓存 我想缓存1~5页 所以 所以 @Caching(evict = { @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 0, 5)"), @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKe

我在页面列表中使用了缓存

我想缓存1~5页

所以

所以

@Caching(evict = {
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 0, 5)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 0, 10)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 0, 25)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 0, 50)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 1, 5)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 1, 10)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 1, 25)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 1, 50)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 2, 5)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 2, 10)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 2, 25)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 2, 50)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 3, 5)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 3, 10)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 3, 25)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 3, 50)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 4, 5)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 4, 10)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 4, 25)"),
    @CacheEvict(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, 4, 50)") })

如何简化此过程?

我认为可以插入CacheManager和…,如下所示:

@Autowired
CacheManager cacheManager;
public Object doSomething() {
    Cache cache = cacheManager.getCache("yourCacheName");
    for (String key : yourKeyIterator) {
        cache.evict(key);
    }
}
我认为这对性能有害,因为调用cache.execute(key)的次数太多了

我认为调用本机缓存实现方法更好

(Ehcache)cache.getNativeCache()...

我把你的钥匙缩进了4格,这样看起来更吸引人。
(Ehcache)cache.getNativeCache()...