有人可以解释一下两者之间的区别吗
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接口(interface)。默认提供了 2 个 CacheManager 的具体实现: EhCacheCacheManager:EhCache的默认实现 ConcurrentMapCacheManager:使用 Java ConcurrentHashMap 作为缓存存储的默认实现。
通过使用 com.googlecode.ehcache.annotations.Cacheable,您可以立即依赖 ehCache 实现。
如果您使用 Spring 注解,如果您稍后想要更改缓存实现,则无需进行任何代码调整,因此我建议使用后者。
关于java - 可缓存注解有什么用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19397937/