【发布时间】:2012-08-07 21:28:06
【问题描述】:
据我所知,使用 EhCache 实现的 Spring (3.1) 内置在 CacheManager 中,根据这篇文章,在代理模式(默认)下存在一定的限制:
Spring 3.1 @Cacheable - method still executed
考虑我的情况:
@CacheEvict(value = "tacos", key = "#tacoId", beforeInvocation = true)
removeTaco(String tacoId) {
// Code to remove taco
}
removeTacos(Set<String> tacoIds) {
for (String tacoId : tacoIds) {
removeTaco(tacoId);
}
}
在此存储库方法中,由于上述限制,调用 removeTacos(tacoIds) 实际上不会从缓存中驱逐任何内容。我的解决方法是,在上面的服务层上,如果我想删除多个 taco,我将遍历每个 taco Id 并将其传递给 removeTaco(),并且从不使用 removeTacos()
不过,我想知道是否还有其他方法可以做到这一点。
1) 是否有一个 SpEL 表达式可以传递给密钥,告诉 EhCache 使 Set 中的每个 id 都过期?
e.g. @CacheEvict(value = "tacos", key = "#ids.?[*]") // I know this isn't valid, just can't find the expression.
或者有没有办法让 removeTacos() 调用 removeTaco 并实际使缓存对象过期?
【问题讨论】:
标签: ehcache spring-3 spring-el