1

I am trying to have two implementations of Cache for different type of objects in my spring boot application. I want to store certain objects in redis cache whereas other object in guava cache based on the method. Whenever I implement two calsses that extend CachingConfigurerSupport, I get an error that only one instance is allowed of this class. Could anyone suggest how I can do this?

mohit_d
  • 235
  • 2
  • 13
  • This is already answered [here](http://stackoverflow.com/questions/34564285/how-to-setup-two-different-cachemanager-in-spring-boot/34587497) – Stephane Nicoll Jan 06 '16 at 09:51
  • So I need to annotate one of the implementation of CacheConfigurer and not the other? Could you please explain this with an example? – mohit_d Jan 07 '16 at 13:55
  • Just implement `CachingConfigurer` for the default one and register an extra bean of type `CacheManager` in your configuration. – Stephane Nicoll Jan 07 '16 at 15:17

2 Answers2

0

you can use CompositeCacheManager like this,

CompositeCacheManager compositeCacheManager = new CompositeCacheManager(
                ehCacheCacheManager(),
                redisCacheManager());

when use cache can specified cacheManage.

@Cacheable(value = "firstCache", key = "#word", cacheManager = "ehCacheCacheManager")

Or

@Caching(
            cacheable = {
                    @Cacheable(value = "firstCache", key = "#word", cacheManager = "ehCacheCacheManager"),
                    @Cacheable(value = "extendInfo", key = "#word", cacheManager = "redisCacheManager")
            }
    )

but i don't know how to update cache cascade. hope it helps.

Tonney Bing
  • 230
  • 2
  • 9
0

Following blog show nice implementation.

Ronen
  • 807
  • 1
  • 13
  • 33