Spring Cache with collection of items/entities

In fact, it is possible, even with Spring’s Caching Abstraction, but not out-of-the-box (OOTB). Essentially, you must customize Spring’s caching infrastructure (Explained further below) By default, Spring’s caching infrastructure uses the entire @Cacheable method parameter arguments as the cache “key”, as explained here. Of course you can also customize the key resolution using either a … Read more

Is it possible to set a different specification per cache using caffeine in spring boot?

This is your only chance: @Bean public CaffeineCache cacheA() { return new CaffeineCache(“CACHE_A”, Caffeine.newBuilder() .expireAfterAccess(1, TimeUnit.DAYS) .build()); } @Bean public CaffeineCache cacheB() { return new CaffeineCache(“CACHE_B”, Caffeine.newBuilder() .expireAfterWrite(7, TimeUnit.DAYS) .recordStats() .build()); } Just expose your custom caches as beans. They are automatically added to the CaffeineCacheManager.

Spring Boot – How to disable @Cacheable during development?

The type of cache is by default automatically detected and configured. However you can specify which cache type to use by adding spring.cache.type to your configuration. To disable it set the value to NONE. As you want to do it for a specific profile add it to that profiles application.properties in this case modify the … Read more

Expiry time @cacheable spring boot

I use life hacking like this: @Configuration @EnableCaching @EnableScheduling public class CachingConfig { public static final String GAMES = “GAMES”; @Bean public CacheManager cacheManager() { ConcurrentMapCacheManager cacheManager = new ConcurrentMapCacheManager(GAMES); return cacheManager; } @CacheEvict(allEntries = true, value = {GAMES}) @Scheduled(fixedDelay = 10 * 60 * 1000 , initialDelay = 500) public void reportCacheEvict() { System.out.println(“Flush … Read more

How to test Spring’s declarative caching support on Spring Data repositories?

If you want to test a technical aspect like caching, don’t use a database at all. It’s important to understand what you’d like to test here. You want to make sure the method invocation is avoided for the invocation with the very same arguments. The repository fronting a database is a completely orthogonal aspect to … Read more

Spring cache @Cacheable method ignored when called from within the same class

This is because of the way proxies are created for handling caching, transaction related functionality in Spring. This is a very good reference of how Spring handles it – Transactions, Caching and AOP: understanding proxy usage in Spring In short, a self call bypasses the dynamic proxy and any cross cutting concern like caching, transaction … Read more

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