- Home
- Skills
- Giuseppe Trisciuoglio
- Developer Kit
- Spring Boot Cache
spring-boot-cache_skill
- Python
99
GitHub Stars
1
Bundled Files
3 weeks ago
Catalog Refreshed
2 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstart where the catalogue uses aiagentskills.
npx veilstart add skill giuseppe-trisciuoglio/developer-kit --skill spring-boot-cache- SKILL.md9.4 KB
Overview
This skill provides a concise, practical workflow for enabling and operating the Spring Cache abstraction in Spring Boot services. It covers adding dependencies, enabling caching, configuring cache managers (Caffeine, Redis, Ehcache), annotating service methods, and validating behavior with tests and observability. The guidance targets Spring Boot 3.5+ projects and focuses on reliable, production-safe caching patterns.
How this skill works
The skill inspects service method boundaries and recommends using @Cacheable for read paths, @CachePut to refresh entries on writes, and @CacheEvict for invalidation. It explains how to declare CacheManager beans, configure cache names and TTLs via properties or customizers, and shape cache keys and conditions with SpEL. It also covers operational concerns: scheduled eviction, Actuator cache endpoints, and Micrometer metrics for hit/miss monitoring.
When to use it
- Implementing application-level caching for performance-sensitive read paths.
- Configuring provider-specific options (Caffeine, Redis, JCache) and TTLs.
- Diagnosing cache key collisions, stale data, or eviction scheduling issues.
- Exposing cache management or scheduled eviction routines for time-sensitive data.
- Validating caching behavior with unit/integration tests and observability stacks.
Best practices
- Prefer constructor injection and immutable DTOs for cached values to avoid mutable state.
- Separate cache names per aggregate (e.g., users, orders) to simplify eviction and metrics.
- Use deterministic SpEL keys and guard caching with condition/unless to prevent caching nulls or undesired entries.
- Tune TTLs based on staleness tolerance and document the rationale near configuration.
- Push cache metrics via Micrometer and keep hit/miss logs at debug level to avoid noise.
Example use cases
- Cache user lookups with Caffeine for low-latency hot-path reads and refresh with @CachePut on updates.
- Use Redis as a shared cache with TTLs and Testcontainers-based integration tests for CI validation.
- Apply conditional caching for expensive queries (e.g., only cache products priced above a threshold).
- Schedule periodic @CacheEvict allEntries=true for time-bound caches like price or inventory snapshots.
- Expose Actuator cache endpoints and Micrometer meters to monitor hit ratio and eviction counts in production.
FAQ
Avoid mixing both on the same method; prefer one annotation style to prevent unpredictable behavior.
How do I prevent caching null results or stale entries?
Use unless = "#result == null" to skip nulls and tune TTLs or scheduled eviction for staleness; consider sync = true for concurrent refreshes.