0

I am using Spring Boot for my application. Using @EnableCaching annotation at application level.

Consider I have multiple cache names like below in some methods on the application

@Cacheable(value = "cache1")
@Cacheable(value = "cache2")
@Cacheable(value = "cache3")
@Cacheable(value = "cache4")
@Cacheable(value = "cache5")

My aim to cache only cache1 for now. So defined following in application.properties

spring.cache.cache-names=cache1
spring.cache.caffeine.spec=maximumSize=100,expireAfterAccess=300s

But when I use the application, I get error like below as it can't find "cache2"

Cannot find cache named 'cache2' for Builder....

I have used multiple cache names in the application. Currently I want to use only cache1 for now. Is it possible to say support only these cache names via some property? How to accomplish it?

Galet
  • 5,853
  • 21
  • 82
  • 148

1 Answers1

0

I'm not quite sure what the goal of this is, but maybe this is a way to do it:

You can define String-constants CACHE_NAME_1 thru 5 somewhere and set them all to "cache1" at first. Use the constants in the @Cacheable as if you had really set it all up properly, so specify CACHE_NAME_3 wherever it is supposed to be "cache3" in the end:

@Cacheable(CACHE_NAME_3)

Whenever you're ready, update the configuration, e.g.

spring.cache.cache-names=cache1,cache2

and assign "cache2" to whichever constant(s).

Rinse and repeat until "cache5".

sjngm
  • 12,423
  • 14
  • 84
  • 114