最近用到Spring 3.1的注解cache.
比如说
@Cacheable(value="posts",key="'getPosts_'+#blogId+'_'+#firstindex+'_'+#maxresult")
public QueryResult<Posts> getPosts(Integer blogId, int firstindex,int maxresult) {
...
}
此时是进行分页的缓存, 表示查询的是blog为id的用户下从firstindex开始一共maxresult条博客文章记录.
但是如果该用户添加或修改了一篇文章 那么这个缓存就要evict.
public void update(Posts post) {
baseDao.update(post);
}
blogId我可以使用Spring el 【#post.blog.id】拿到,这个时候我要清理缓存就要进行模糊的匹配
类似于这样的
@CacheEvict(value="posts",key="'getPosts_'+#post.blogs.id+'_*'"),
就是把【#firstindex+'_'+#maxresult】换成了【*】.但是Spring EL不支持这样的写法.
查了文档也没看到Spring EL支持*匹配的.
不知道怎么个写法能解决这个问题,或者说换个换个缓存的思路?
Spring
Ehcache
Hibernate
引用来自“王振威”的答案