Card 07/ 07
Recap: Caching in Spring Boot
The three annotations, keys, strategies, and the default cache's single-instance limit.
Caching in Spring Boot comes down to the five ideas below, each listed with the card that covers it.
| The idea | Where |
|---|---|
@EnableCaching switches caching on; @Cacheable skips the method on a hit | Spring Caching: @EnableCaching and @Cacheable |
@CachePut always runs and refreshes; @CacheEvict removes an entry | @Cacheable vs @CachePut vs @CacheEvict |
| The key comes from the arguments, so different arguments are different entries | Cache Keys Example: One Entry per Argument |
| Evicting on write is cache-aside; putting on write is close to write-through | Caching Strategies: Cache-Aside vs Write-Through |
| The default in-memory cache goes stale across several instances | The Default In-Memory Cache With More Than One Instance |
Before caching a method, answer three questions: what the key is, how a change reaches the cache, and how many instances will share it.
← → move through sections and cards