Card 07/ 07

RecapDifficulty: Advanced1 min

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.

What the topic established, and which card it was on
The ideaWhere
@EnableCaching switches caching on; @Cacheable skips the method on a hitSpring 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 entriesCache Keys Example: One Entry per Argument
Evicting on write is cache-aside; putting on write is close to write-throughCaching Strategies: Cache-Aside vs Write-Through
The default in-memory cache goes stale across several instancesThe 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.