How to cache results of a Spring Data JPA query method without using query cache?

The reason the code you have is not working is that @Cache is not intended to work that way. If you want to cache the results of a query method execution, the easiest way is to use Spring’s caching abstraction. interface PromotionServiceXrefRepository extends PagingAndSortingRepository<PromotionServiceXref, Integer> { @Query(“…”) @Cacheable(“servicesByCustomerId”) Set<PromotionServiceXref> findByCustomerId(int customerId); @Override @CacheEvict(value = “servicesByCustomerId”, … Read more

Using Spring cache annotation in multiple modules

Use this class: http://static.springsource.org/autorepo/docs/spring/3.2.0.M1/api/org/springframework/cache/support/CompositeCacheManager.html like this: <cache:annotation-driven cache-manager=”cacheManager” /> <bean id=”cacheManager” class=”org.springframework.cache.support.CompositeCacheManager”> <property name=”cacheManagers”> <array> <ref bean=”cacheManager1″ /> <ref bean=”cacheManager2″ /> </array> </property> <property name=”addNoOpCache” value=”true” /> </bean>

How to disable the Ehcache update checker?

One way is to place a ehcache.xml file on your classpath with the attribute updateCheck=”false” in the root tag. For example: <ehcache updateCheck=”false”> <defaultCache maxElementsInMemory=”0″ eternal=”false” timeToIdleSeconds=”0″ timeToLiveSeconds=”0″ overflowToDisk=”false” diskPersistent=”false”/> </ehcache> Another way is to set an environment variable: System.setProperty(“net.sf.ehcache.skipUpdateCheck”, “true”);

SingletonEhCacheRegionFactory vs EhCacheRegionFactory

The non-singleton EhCacheRegionFactory allows you to configure EHCache separately for each Hibernate instance using net.sf.ehcache.configurationResourceName property. The SingletonEhCacheRegionFactory shares the same EHCache configuration among all Hibernate session factories. EHCache documentation recommends to use the non-singleton version. Edit: This information applies to EHCache 2.8. Not sure how many things have changed in the latest version.

hello world example for ehcache?

EhCache comes with a failsafe configuration that has some reasonable expiration time (120 seconds). This is sufficient to get it up and running. Imports: import net.sf.ehcache.CacheManager; import net.sf.ehcache.Element; Then, creating a cache is pretty simple: CacheManager.getInstance().addCache(“test”); This creates a cache called test. You can have many different, separate caches all managed by the same CacheManager. … Read more

Redis or Ehcache?

You can think Redis as a shared data structure, while Ehcache is a memory block storing serialized data objects. This is the main difference. Redis as a shared data structure means you can put some predefined data structure (such as String, List, Set etc) in one language and retrieve it in another language. This is … 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

Getting `Can’t assign requested address` java.net.SocketException using Ehcache multicast

This was caused by an IPv6 address being returned from java.net.NetworkInterface.getDefault(). I’m on a Macbook and was using wireless — p2p0 (used for AirDrop) was returned as the default network interface but my p2p0 only has an IPv6 ether entry (found by running ipconfig). Two solutions, both of which worked for me (I prefer the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)