![](/img/trans.png)
[英]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.