Another unnamed CacheManager already exists in the same VM (ehCache 2.5)

Your EhCacheManagerFactoryBean may be a singleton, but it’s building multiple CacheManagers and trying to give them the same name. That violates Ehcache 2.5 semantics. Versions of Ehcache before version 2.5 allowed any number of CacheManagers with the same name (same configuration resource) to exist in a JVM. Ehcache 2.5 and higher does not allow multiple … Read more

@Cacheable key on multiple method arguments

Update: Current Spring cache implementation uses all method parameters as the cache key if not specified otherwise. If you want to use selected keys, refer to Arjan’s answer which uses SpEL list {#isbn, #includeUsed} which is the simplest way to create unique keys. From Spring Documentation The default key generation strategy changed with the release … Read more

Using EhCache in Spring 4 without XML

XML-less configuration of EhCache in Spring @Configuration @EnableCaching public class CachingConfig implements CachingConfigurer { @Bean(destroyMethod=”shutdown”) public net.sf.ehcache.CacheManager ehCacheManager() { CacheConfiguration cacheConfiguration = new CacheConfiguration(); cacheConfiguration.setName(“myCacheName”); cacheConfiguration.setMemoryStoreEvictionPolicy(“LRU”); cacheConfiguration.setMaxEntriesLocalHeap(1000); net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration(); config.addCache(cacheConfiguration); return net.sf.ehcache.CacheManager.newInstance(config); } @Bean @Override public CacheManager cacheManager() { return new EhCacheCacheManager(ehCacheManager()); } @Bean @Override public KeyGenerator keyGenerator() { return new SimpleKeyGenerator(); … Read more

Spring Cache @Cacheable – not working while calling from another method of the same bean

I believe this is how it works. From what I remember reading, there is a proxy class generated that intercepts all requests and responds with the cached value, but ‘internal’ calls within the same class will not get the cached value. From https://code.google.com/p/ehcache-spring-annotations/wiki/UsingCacheable Only external method calls coming in through the proxy are intercepted. This … Read more