Back to Skills

spring-boot-cache

Provides patterns for implementing Spring Boot caching: configures Redis/Caffeine/EhCache providers with TTL and eviction policies, applies @Cacheable/@CacheEvict/@CachePut annotations, validates cache hit/miss behavior, and exposes metrics via Actuator. Use when adding caching to Spring Boot services, configuring cache expiration, evicting stale data, or diagnosing cache misses.

312stars37forksUpdated 7/30/2026

Security Assessment

Safe(95/100)
Security Score95/100

About spring-boot-cache

This skill provides patterns for implementing caching in Spring Boot services using Spring's cache abstraction. It solves the problem of adding, configuring, and validating caching correctly by walking through a six-step workflow covering provider selection, cache enabling, method annotation, TTL/eviction policy configuration, key shaping, and behavior validation for Spring Boot 3.5+ applications.

The skill documents when and how to apply @Cacheable for reads, @CachePut for writes, and @CacheEvict for deletions, and how to configure Caffeine, Redis, or Ehcache providers with TTL and capacity policies via application properties. It shows SpEL-based key shaping with condition/unless guards for selective caching, and validation via integration tests plus Actuator endpoints (GET /actuator/caches and GET /actuator/metrics/cache.gets for hit/miss ratios). Advanced options cover JCache/JSR-107 annotations, caching reactive (Mono/Flux) and CompletableFuture return types, HTTP CacheControl headers, and scheduled eviction. A troubleshooting section addresses the classic causes of persistent cache misses — missing @EnableCaching, self-invocation bypassing proxies, bad SpEL keys, and cache-manager bean naming. Reference files provide a full annotation/parameter API reference, dependency matrices, property catalogs, curated Spring Framework documentation excerpts, and end-to-end examples with tests.

It targets Java and Spring Boot developers adding caching to services, configuring cache expiration and eviction, or diagnosing why cached values aren't being hit. The content is standard framework guidance and configuration reference — Redis connection properties document host, port, and password fields for local setup without any credential exfiltration.

FAQ

Which cache providers are covered?

Caffeine, Redis, and Ehcache (plus the simple in-memory ConcurrentMapCacheManager), each with dependency setup and TTL/eviction configuration via application properties or YAML.

How do I validate that caching works?

Run an integration test confirming a cache hit on the second call, check GET /actuator/caches to verify the cache manager is registered, and query GET /actuator/metrics/cache.gets for hit/miss ratios.

Why are my cache misses persisting after adding @Cacheable?

Common causes: @EnableCaching is missing on a @Configuration class; the method isn't public or is called via self-invocation (which bypasses the Spring proxy); the SpEL key expression doesn't resolve; or the cache manager bean isn't named cacheManager or referenced explicitly.

Which annotation do I use for what?

@Cacheable for reads (cache before execution), @CachePut for writes (always execute then cache), and @CacheEvict for deletions, with condition/unless SpEL guards for selective caching.

What Spring Boot version does it target?

Spring Boot 3.5+, with reference dependencies pinned to versions like spring-boot-starter-cache 3.5.6, Caffeine 3.1.6, and Ehcache 3.10.8.

All Files

5 files
references/cache-core-reference.md15.5 KB
View
references/spring-cache-doc-snippet.md15.1 KB
View
SKILL.md5.4 KB
View
references/cache-examples.md17.2 KB
View
references/spring-framework-cache-docs.md3.9 KB
View

Install spring-boot-cache

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill