Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

How to create a secondary CacheManager without overriding default spring-cache

$
0
0

I have a default redis cache configuration in my application.yml:

cache:
    type: redis
    redis:
      time-to-live: 7200000 # 2 hour TTL - Tune this if needed later
  redis:
    host: myHost
    port: myPort
    password: myPass
    ssl: true
    cluster:
      nodes: clusterNodes
    timeout: 10000

It works great and I don't want to create any custom cache manager for it.

However, there are some caches in my code where using redis is not necessary. For that reason, I want to make a second CacheManager that's a simple ConcurrentHashMap and specify it with @Cacheable

To do that I created a new CacheManager Bean:


@Configuration
@EnableCaching
@Slf4j
class CachingConfiguration {

    @Bean(name = "inMemoryCache")
    public CacheManager inMemoryCache() {
        SimpleCacheManager cache = new SimpleCacheManager();
        cache.setCaches(Arrays.asList(new ConcurrentMapCache("CACHE"));
        return cache;
    }

}

This causes the inMemoryCache to be my default cache and all my other @Cacheable() tried to use the inMemoryCache. I don't want the CacheManager bean that I created to be my default. Is there anyway I can specify that it's secondary and not prevent spring-cache for doing it's magic?

Thanks!


Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>