我习惯在页面列表中使用缓存。
我想要1~5页缓存。
所以,
@Cacheable(value = "cacheData", key = "T(com.insoft.pacific.util.CacheKeyGenerator).cacheKey(#root.targetClass, #pageIndex, #pagePerNumber)", condition = "#pageIndex < 5")关键字如下:
'brandon@[EventChainServiceImpl]0/10'
'brandon@[EventChainServiceImpl]1/10'
'brandon@[EventChainServiceImpl]2/10'所以,
@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)") })我怎么才能简化这个过程呢?
发布于 2016-05-29 21:07:31
我认为你可以注入CacheManager和...,就像这样:
@Autowired
CacheManager cacheManager;
public Object doSomething() {
Cache cache = cacheManager.getCache("yourCacheName");
for (String key : yourKeyIterator) {
cache.evict(key);
}
}我认为这对性能是有害的,因为需要多次调用cache.evict(key)。
我认为调用本机缓存实现方法更好。
(Ehcache)cache.getNativeCache()...https://stackoverflow.com/questions/28959402
复制相似问题