cache_patterns

Configures Spring Cache abstraction with annotation-driven caching in Spring Boot services.

Updated Jan 14, 2026
One-click install
npx skills add https://github.com/jvsandhu/agentic-skills --skill cache-patterns-jvsandhu
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cache_patterns
Source: https://github.com/jvsandhu/agentic-skills/tree/main/skills/cache_patterns
Command: npx skills add https://github.com/jvsandhu/agentic-skills --skill cache-patterns-jvsandhu

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Repeated expensive service calls and database reads slow down Spring Boot applications, and implementing caching correctly requires coordinating providers, annotations, eviction policies, and monitoring without introducing stale data or consistency bugs. ## Core Features & Use Cases - Annotation-Driven Caching: Apply @Cacheable, @CachePut, and @CacheEvict to service methods with SpEL-based key strategies. - Provider Configuration: Set up Caffeine, Redis, Ehcache, or JCache cache managers without changing business code. - Lifecycle Monitoring: Configure TTL and eviction policies, then audit hit/miss ratios through the Actuator cache endpoint. - Use Case: A user service with frequent profile lookups can add @Cacheable on the finder method, evict entries on updates, and verify with tests that the repository is only invoked once per key. ## Quick Start Ask the agent to enable Spring caching in your Spring Boot 3.5 project by adding a Caffeine cache manager and annotating a service method with @Cacheable.

Frequently Asked Questions about cache_patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enable caching in a Spring Boot application?

Add the spring-boot-starter-cache dependency, annotate a configuration class with @EnableCaching, and declare a CacheManager bean such as CaffeineCacheManager. Then annotate service methods with @Cacheable to store and reuse results.

What is the difference between @Cacheable, @CachePut, and @CacheEvict?

@Cacheable reads from the cache and only executes the method on a miss. @CachePut always executes the method and refreshes the cached value. @CacheEvict removes entries, optionally clearing all entries with allEntries=true.

Should I use Caffeine or Redis as a Spring cache provider?

Caffeine suits single-instance, in-memory caching with low latency. Redis fits distributed systems where multiple service instances must share cache state. Both integrate through Spring's CacheManager abstraction without changing business code.

Can I mix Spring cache annotations with JCache annotations?

No, you should not mix Spring annotations like @Cacheable with JCache annotations like @CacheResult on the same method. Choose one annotation model per method to avoid conflicting interception behavior.

How do I monitor cache hit and miss ratios in Spring Boot?

Enable the Actuator cache endpoint to inspect cache statistics, and push metrics through Micrometer for production monitoring. Keep hit/miss logging at debug level to avoid log noise.

Why does my Spring cache return stale data after updates?

Stale data occurs when eviction is not aligned with transactional boundaries or when @CachePut is missing on update methods. Align cache eviction with transaction commits and use publish/subscribe invalidation for multi-instance deployments.