简体   繁体   English

可缓存注释的用途是什么

[英]What is the use of Cacheable Annotation

can somebody please explain what is the difference between 有人可以解释一下

com.googlecode.ehcache.annotations.Cacheable and org.springframework.cache.annotation.Cacheable com.googlecode.ehcache.annotations.Cacheable和org.springframework.cache.annotation.Cacheable

if i replace first one with second one what will be the effect ?? 如果我用第二个替换第一个,将会有什么效果?

I have used @Cacheable in a web service coded using spring 我在使用spring编码的Web服务中使用了@Cacheable

@Cacheable(value = "policyCache")
public ResponseEntity<ResponseVO> listById(@PathVariable(value = "id") )

Spring 3 introduces a new abstraction layer for caching services. Spring 3引入了用于缓存服务的新抽象层。 The idea is to provide a set of common features, mainly annotations, to activate and manage the caches. 这个想法是提供一组常用功能(主要是注释)来激活和管理缓存。 Since it is only an abstract layer, Spring 3 caching still need a concrete implementation to work. 由于它只是一个抽象层,因此Spring 3缓存仍需要一个具体的实现才能起作用。 The entry point for cache implementation is the CacheManager interface. 缓存实现的入口点是CacheManager接口。 By default 2 concrete implementation of CacheManager are provided: EhCacheCacheManager: default implementation for EhCache ConcurrentMapCacheManager: default implementation using Java ConcurrentHashMap as cache store. 默认情况下,提供CacheManager的2种具体实现:EhCacheCacheManager:EhCache的默认实现ConcurrentMapCacheManager:使用Java ConcurrentHashMap作为缓存存储的默认实现。

With the use of com.googlecode.ehcache.annotations.Cacheable, you rely immediately on the ehCache implementation. 通过使用com.googlecode.ehcache.annotations.Cacheable,您可以立即依赖ehCache实现。

If you use the Spring annotations, you don't have to do any code adaptations if you want to change your cache implementation later on, so I would advise to use the latter. 如果使用Spring批注,则以后如果要更改缓存实现,则不必进行任何代码修改,因此建议您使用后者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM