spring-boot-cache

Solid

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.

AI & Automation 278 stars 32 forks Updated 5 days ago MIT

Install

View on GitHub

Quality Score: 91/100

Stars 20%
81
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Spring Boot Cache Abstraction ## Overview 6-step workflow for enabling cache abstraction, configuring providers (Caffeine, Redis, Ehcache), annotating service methods, and validating behavior in Spring Boot 3.5+ applications. Apply `@Cacheable` for reads, `@CachePut` for writes, `@CacheEvict` for deletions. Configure TTL/eviction policies and expose metrics via Actuator. ## When to Use - Add `@Cacheable`, `@CachePut`, or `@CacheEvict` to service methods. - Configure Caffeine, Redis, or Ehcache with TTL and capacity policies. - Implement eviction strategies for stale data. - Diagnose cache misses or invalidation issues. - Expose hit/miss metrics via Actuator or Micrometer. ## Instructions 1. **Add dependencies** — `spring-boot-starter-cache` plus a provider: - Caffeine: `caffeine` starter - Redis: `spring-boot-starter-data-redis` - Ehcache: `ehcache` starter 2. **Enable caching** — annotate a `@Configuration` class with `@EnableCaching` and define a `CacheManager` bean. 3. **Annotate methods** — `@Cacheable` for reads, `@CachePut` for writes, `@CacheEvict` for deletions. 4. **Configure TTL/eviction** — set `spring.cache.caffeine.spec`, `spring.cache.redis.time-to-live`, or `spring.cache.ehcache.config`. 5. **Shape keys** — use SpEL in `key` attributes; guard with `condition`/`unless` for selective caching. 6. **Validate setup** — run integration test to confirm cache hit on second call; check `GET /actuator/caches` to verify cache manager r...

Details

Author
giuseppe-trisciuoglio
Repository
giuseppe-trisciuoglio/developer-kit
Created
7 months ago
Last Updated
5 days ago
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category