@Cacheable Articles
3 articles about @Cacheable. Explore Spring Boot implementation, design, and operations across related topics.
-
How to Control Cache Keys with @Cacheable in Spring Boot - Choosing Between SpEL in the key Attribute, KeyGenerator, condition/unless, and @Caching
You added @Cacheable, yet different arguments return the same result, or null values end up cached. This guide covers Spring Boot 3.x: the key resolution rules of SimpleKeyGenerator, SpEL in the key attribute, custom KeyGenerator implementations, condition/unless, and when to use @Caching, and finishes with tests that verify cache keys using Caffeine stats.
-
Why @Transactional, @Cacheable, and @Async Don't Work in Spring Boot - Understanding AOP Proxies and Self-Invocation to Fix It
@Transactional doesn't roll back, @Cacheable hits the DB every time, @Async runs synchronously. All of these are caused by how Spring AOP proxies work. This article isolates five patterns - self-invocation, private/final methods, new, and missing enablement - with reproducible code and diagnostic steps, then compares workarounds such as extracting to a separate Bean, self-injection, and TransactionTemplate.
-
How to Use Spring Boot Caching - Easy Performance Improvements with @Cacheable
A hands-on guide covering how Spring Cache Abstraction works, how to use @Cacheable, @CacheEvict, and @CachePut, key design with @CacheConfig and KeyGenerator, switching to Caffeine and Redis with per-cache TTLs, and measuring hit rates with Micrometer, all with practical code examples. Aimed at beginner-to-intermediate developers who want to fix response latency caused by redundant DB or external API calls with just a few lines of annotations.