/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
$ npx -y skills add giuseppe-trisciuoglio/developer-kit --skill spring-boot-cache --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.
- You can call itInvoke it directly when you want it.
- Slash command
/spring-boot-cache
Context preview
The summary Claude sees to decide when to auto-load this skill.
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
SKILL.md
spring-boot-cache.SKILL.mdname: spring-boot-cache
description: "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."
allowed-tools: Read, Write, Bash
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 registration; query `GET /actuator/metrics/cache.gets` for hit/miss ratios.
Examples
Example 1: Basic `@Cacheable` Usage
@Service
@CacheConfig(cacheNames = "users")
class UserService {
@Cacheable(key = "#id", unless = "#result == null")
User findUser(Long id) { ... }
}First call → cache miss, repository invoked
Second call → cache hit, repository skipped
Example 2: Conditional Caching with SpEL
@Cacheable(value = "products", key = "#id", condition = "#price > 100")
public Product getProduct(Long id, BigDecimal price) { ... }
// Only expensive products are cachedExample 3: Cache Eviction
@CacheEvict(value = "users", key = "#id")
public void deleteUser(Long id) { ... }For progressive scenarios (basic product cache, multilevel eviction, Redis integration), load [`references/cache-examples.md`](references/cache-examples.md).
Advanced Options
- Use JCache annotations (`@CacheResult`, `@CacheRemove`) for providers favoring
JSR-107 interoperability; avoid mixing with Spring annotations on the same method.
- Cache reactive return types (`Mono`, `Flux`) or `CompletableFuture` values.
- Apply HTTP `CacheControl` headers when exposing cached responses via REST.
- Schedule periodic eviction with `@Scheduled` for time-bound caches.
- Create a `CacheManagementService` for programmatic `cacheManager.getCache(name)`.
Troubleshooting
If cache misses persist after adding `@Cacheable`:
1. Verify `@EnableCaching` is present on a `@Configuration` class. 2. Confirm the method is public and called from outside the class (Spring uses proxies; self-invocation bypasses the cache). 3. Validate SpEL key expressions resolve correctly. 4. Confirm the cache manager bean is registered as `cacheManager` or explicitly referenced via `cacheManager = "myCacheManager"`.
References
- [`references/spring-framework-cache-docs.md`](references/spring-framework-cache-docs.md):
curated excerpts from Spring Framework Reference Guide.
- [`references/spring-cache-doc-snippet.md`](references/spring-cache-doc-snippet.md):
narrative overview from Spring documentation.
- [`references/cache-core-reference.md`](references/cache-core-reference.md):
annotation parameters, dependency matrices, property catalogs.
- [`references/cache-examples.md`](references/cache-examples.md):
end-to-end examples with tests.
Best Practices
- Prefer constructor injection and immutable DTOs for cache entries.
- Separate cache names per aggregate (`users`, `orders`) to simplify eviction.
- Log cache hits/misses only at debug; push metrics via Micrometer.
- Tune TTLs based on data staleness tolerance; document rationale in code.
- Guard caches storing PII or credentials with encryption or avoid caching.
- Align cache eviction with transactional boundaries to prevent dirty reads.
Constraints and Warnings
- Avoid caching mutable entities that depend on open persistence contexts.
- Do not mix Spring cache annotations with JCache annotations on the same method.
- Validate serialization compatibility when caching across service instances.
- Monitor memory footprint to prevent OOM with in-memory stores.
- Caffeine + Redis multi-level caches require publish/subscribe invalidation channels.
Related Skills
- [`../spring-boot-rest-api-standards`](../spring-boot-rest-api-standards/SKILL.md)
- [`../spring-boot-test-patterns`](../spring-boot-test-patterns/SKILL.md)
- [`../unit-test-caching`](../unit-test-caching/SKILL.md)
Read more
name: spring-boot-cache description: "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." allowed-tools: Read, Write, Bash
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 registration; query `GET /actuator/metrics/cache.gets` for hit/miss ratios.
Examples
Example 1: Basic `@Cacheable` Usage
@Service
@CacheConfig(cacheNames = "users")
class UserService {
@Cacheable(key = "#id", unless = "#result == null")
User findUser(Long id) { ... }
}First call → cache miss, repository invoked Second call → cache hit, repository skipped
Example 2: Conditional Caching with SpEL
@Cacheable(value = "products", key = "#id", condition = "#price > 100")
public Product getProduct(Long id, BigDecimal price) { ... }
// Only expensive products are cachedExample 3: Cache Eviction
@CacheEvict(value = "users", key = "#id")
public void deleteUser(Long id) { ... }For progressive scenarios (basic product cache, multilevel eviction, Redis integration), load [`references/cache-examples.md`](references/cache-examples.md).
Advanced Options
- Use JCache annotations (`@CacheResult`, `@CacheRemove`) for providers favoring
JSR-107 interoperability; avoid mixing with Spring annotations on the same method.
- Cache reactive return types (`Mono`, `Flux`) or `CompletableFuture` values.
- Apply HTTP `CacheControl` headers when exposing cached responses via REST.
- Schedule periodic eviction with `@Scheduled` for time-bound caches.
- Create a `CacheManagementService` for programmatic `cacheManager.getCache(name)`.
Troubleshooting
If cache misses persist after adding `@Cacheable`:
1. Verify `@EnableCaching` is present on a `@Configuration` class. 2. Confirm the method is public and called from outside the class (Spring uses proxies; self-invocation bypasses the cache). 3. Validate SpEL key expressions resolve correctly. 4. Confirm the cache manager bean is registered as `cacheManager` or explicitly referenced via `cacheManager = "myCacheManager"`.
References
- [`references/spring-framework-cache-docs.md`](references/spring-framework-cache-docs.md):
curated excerpts from Spring Framework Reference Guide.
- [`references/spring-cache-doc-snippet.md`](references/spring-cache-doc-snippet.md):
narrative overview from Spring documentation.
- [`references/cache-core-reference.md`](references/cache-core-reference.md):
annotation parameters, dependency matrices, property catalogs.
- [`references/cache-examples.md`](references/cache-examples.md):
end-to-end examples with tests.
Best Practices
- Prefer constructor injection and immutable DTOs for cache entries.
- Separate cache names per aggregate (`users`, `orders`) to simplify eviction.
- Log cache hits/misses only at debug; push metrics via Micrometer.
- Tune TTLs based on data staleness tolerance; document rationale in code.
- Guard caches storing PII or credentials with encryption or avoid caching.
- Align cache eviction with transactional boundaries to prevent dirty reads.
Constraints and Warnings
- Avoid caching mutable entities that depend on open persistence contexts.
- Do not mix Spring cache annotations with JCache annotations on the same method.
- Validate serialization compatibility when caching across service instances.
- Monitor memory footprint to prevent OOM with in-memory stores.
- Caffeine + Redis multi-level caches require publish/subscribe invalidation channels.
Related Skills
- [`../spring-boot-rest-api-standards`](../spring-boot-rest-api-standards/SKILL.md)
- [`../spring-boot-test-patterns`](../spring-boot-test-patterns/SKILL.md)
- [`../unit-test-caching`](../unit-test-caching/SKILL.md)
Modular plugin marketplace for Claude Code and agentic CLIs, with validated, spec-driven skills, agents, commands, and workflows for Java, TypeScript, Python, PHP, AWS, and AI.
Repo: giuseppe-trisciuoglio/developer-kit
Other skills on developer-kit.
- /chunking-strategy
Provides chunking strategies for RAG systems. Generates chunk size recommendations (256-1024 tokens), overlap percentages (10-20%), and semantic boundary detection methods. Validates semantic coherence and evaluates retrieval precision/recall metrics. Use when building
Open skill - /prompt-engineering
Provides workflows to write, debug, and optimize prompts for LLMs, including few-shot example selection, chain-of-thought structuring, system prompt design, and template composition. Use when the user asks to write or improve a prompt, wants help with few-shot examples,
Open skill - /rag
Implements document chunking, embedding generation, vector storage, and retrieval pipelines for Retrieval-Augmented Generation systems. Use when building RAG applications, creating document Q&A systems, or integrating AI with knowledge bases.
Open skill - /aws-cloudformation-auto-scaling
Provides AWS CloudFormation patterns for Auto Scaling including EC2, ECS, and Lambda. Use when creating Auto Scaling groups, launch configurations, launch templates, scaling policies, lifecycle hooks, and predictive scaling. Covers template structure with Parameters, Outputs,
Open skill - /aws-cloudformation-bedrock
Provides AWS CloudFormation patterns for Amazon Bedrock resources including agents, knowledge bases, data sources, guardrails, prompts, flows, and inference profiles. Use when creating Bedrock agents with action groups, implementing RAG with knowledge bases, configuring vector
Open skill - /aws-cloudformation-cloudfront
Provides AWS CloudFormation patterns for CloudFront distributions, origins (ALB, S3, Lambda@Edge, VPC Origins), CacheBehaviors, Functions, SecurityHeaders, parameters, Outputs and cross-stack references. Use when creating CloudFront distributions with CloudFormation, configuring
Open skill

