0
0
Spring Bootframework~5 mins

@Cacheable for read caching in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the @Cacheable annotation do in Spring Boot?

The @Cacheable annotation tells Spring to save the result of a method call in a cache. When the method is called again with the same parameters, Spring returns the cached result instead of running the method again. This speeds up read operations.

Click to reveal answer
beginner
How do you specify which cache to use with @Cacheable?

You use the value or cacheNames attribute inside @Cacheable to name the cache. For example, @Cacheable("books") tells Spring to use the cache named "books".

Click to reveal answer
intermediate
What happens if the method parameters change when using @Cacheable?

Spring uses the method parameters as keys in the cache. If parameters change, Spring treats it as a new request and runs the method, then caches the new result separately.

Click to reveal answer
intermediate
Can @Cacheable be used for write operations?

No, @Cacheable is meant for read caching only. For write or update operations, you use @CachePut or @CacheEvict to update or clear the cache.

Click to reveal answer
beginner
What is a simple example of using @Cacheable in a Spring Boot service method?
  @Cacheable("items")
  public Item getItemById(Long id) {
    // Simulate slow database call
    return repository.findById(id).orElse(null);
  }

This caches the result of getItemById so repeated calls with the same id are faster.

Click to reveal answer
What does @Cacheable do in Spring Boot?
ADisables caching for a method
BDeletes data from the database
CUpdates the cache after a write operation
DCaches the result of a method to speed up repeated reads
Which attribute specifies the cache name in @Cacheable?
Avalue or cacheNames
Bkey
Ccondition
Dsync
If method parameters change, what does Spring do with @Cacheable?
AThrows an error
BReturns the old cached result anyway
CRuns the method and caches the new result separately
DClears the entire cache
Which annotation should you use to update the cache after a write operation?
A@CachePut
B@Cacheable
C@CacheEvict
D@CacheDelete
What is a benefit of using @Cacheable?
AEncrypts data in the cache
BImproves performance by avoiding repeated slow calls
CAutomatically backs up the database
DPrevents method execution
Explain how @Cacheable works in Spring Boot and why it is useful for read operations.
Think about how saving answers helps when you get the same question again.
You got /4 concepts.
    Describe the difference between @Cacheable, @CachePut, and @CacheEvict in Spring Boot caching.
    Consider reading, updating, and deleting cache entries.
    You got /3 concepts.