Bird
0
0

A developer wrote this code:

medium📝 Debug Q7 of 15
Spring Boot - Caching
A developer wrote this code:
@Cacheable("users")
public void saveUser(User user) {
  userRepository.save(user);
}

Why does caching not work as expected?
AMethod returns void, so no result to cache
BMissing @EnableCaching annotation
CCache name "users" is invalid
DRedis server is down
Step-by-Step Solution
Solution:
  1. Step 1: Analyze method return type

    @Cacheable caches method return values; void methods return nothing, so nothing to cache.
  2. Step 2: Check other options

    Missing @EnableCaching disables caching globally but question focuses on method; cache name "users" is valid; Redis server down causes errors, not silent no caching.
  3. Final Answer:

    Method returns void, so no result to cache -> Option A
  4. Quick Check:

    @Cacheable requires non-void return to cache [OK]
Quick Trick: @Cacheable needs a return value to cache [OK]
Common Mistakes:
  • Using @Cacheable on void methods
  • Ignoring need for @EnableCaching
  • Assuming cache name invalid disables caching

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes