我是EhCache的新手,所以也许我的问题很傻,但无论如何:我使用EhCache与Spring。然后在我的DAO中写入这个:
@Cacheable(value="product", key="#id")
public Product getProductById(Integer id) {//some code;}
@Cacheable(value="productList")
public List<Product> getAllProducts() {//some code;}
当我删除或更新一些产品时,我想更新我的productList缓存。我可以在我的代码中做这样的事情来解决这个问题吗(在这个例子中,productList和product缓存都被删除了):
@Caching(evict={@CacheEvict(value="productList", allEntries=true), @CacheEvict(value="product", key="#id")})
public boolean deleteProductById(Integer id) { //some code;}
也许,有一些方法可以做到这一点没有注释。如有任何建议,我都很高兴。谢谢你。
对我来说是这样的
@CacheEvict(value="productList", allEntries=true)
public boolean deleteProductById(Integer id) {
//some code;
}