Can somebody please explain what is the difference between
com.googlecode.ehcache.annotations.Cacheable
and
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
@Cacheable(value = "policyCache")
public ResponseEntity<ResponseVO> listById(@PathVariable(value = "id") )
Spring 3 introduces a new abstraction layer for caching services. 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. The entry point for cache implementation is the CacheManager
interface. By default 2 concrete implementation of CacheManager
are provided:
EhCacheCacheManager
: default implementation for EhCache
ConcurrentMapCacheManager
: default implementation using Java ConcurrentHashMap
as cache store.
With the use of com.googlecode.ehcache.annotations.Cacheable
, you rely immediately on the ehCache
implementation.
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.