阅读有关新的内容缓存抽象 http://blog.springsource.org/2011/02/23/spring-3-1-m1-caching/在 Spring 3.1 中,我想将此功能应用到我的项目中。
我可以缓存对没有参数的方法的调用吗?
@Cacheable("xCache")
public List<X> loadAllX() {
...
}
链接的博客文章指出
使用方法参数作为关键来执行缓存查找
所以应该不可能缓存这个方法,对吗?
简短回答:是的,没有任何参数的方法将像任何其他方法一样被缓存。我猜想该方法的缓存中将只有一个条目。
您可以通过使用“缓存 SpEL 可用元数据”如此处所述:
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/cache.html#cache-spel-context http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/cache.html#cache-spel-context
在您的示例中,您可以指定以下内容:
@Cacheable(value = "xCache", key = "#root.methodName")
public List<X> loadAllX() {
...
}
它将使用键“loadAllX”将 X 列表缓存在“xCache”中
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)