Bird
0
0

You want to enable caching only for a specific cache manager in your Spring Boot app. How can you configure @EnableCaching to use a custom cache manager bean named myCacheManager?

hard📝 Application Q8 of 15
Spring Boot - Caching
You want to enable caching only for a specific cache manager in your Spring Boot app. How can you configure @EnableCaching to use a custom cache manager bean named myCacheManager?
AUse <code>@EnableCaching(cacheManager="myCacheManager")</code>
BUse <code>@EnableCaching</code> and define a bean named <code>myCacheManager</code>
CUse <code>@EnableCaching</code> with <code>@CacheConfig(cacheManager="myCacheManager")</code> on classes
DUse <code>@EnableCaching</code> with <code>@Cacheable(cacheManager="myCacheManager")</code> on methods
Step-by-Step Solution
Solution:
  1. Step 1: Understand @EnableCaching parameters

    @EnableCaching does not accept cacheManager attribute directly.
  2. Step 2: Use @CacheConfig for cache manager selection

    @CacheConfig on classes can specify cacheManager to use for caching annotations.
  3. Final Answer:

    Use @EnableCaching and @CacheConfig(cacheManager="myCacheManager") on classes -> Option C
  4. Quick Check:

    @CacheConfig sets cacheManager, not @EnableCaching [OK]
Quick Trick: Use @CacheConfig(cacheManager) on class to select cache manager [OK]
Common Mistakes:
  • Trying to set cacheManager on @EnableCaching
  • Setting cacheManager on @Cacheable methods
  • Not defining the cache manager bean

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes