[英]What is the best way of defining key for @Cacheable annotation for Spring
[英]What is the use of Cacheable Annotation
有人可以解释一下
com.googlecode.ehcache.annotations.Cacheable和org.springframework.cache.annotation.Cacheable
如果我用第二个替换第一个,将会有什么效果?
我在使用spring编码的Web服务中使用了@Cacheable
@Cacheable(value = "policyCache")
public ResponseEntity<ResponseVO> listById(@PathVariable(value = "id") )
Spring 3引入了用于缓存服务的新抽象层。 这个想法是提供一组常用功能(主要是注释)来激活和管理缓存。 由于它只是一个抽象层,因此Spring 3缓存仍需要一个具体的实现才能起作用。 缓存实现的入口点是CacheManager接口。 默认情况下,提供CacheManager的2种具体实现:EhCacheCacheManager:EhCache的默认实现ConcurrentMapCacheManager:使用Java ConcurrentHashMap作为缓存存储的默认实现。
通过使用com.googlecode.ehcache.annotations.Cacheable,您可以立即依赖ehCache实现。
如果使用Spring批注,则以后如果要更改缓存实现,则不必进行任何代码修改,因此建议您使用后者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.