mcpbeat Sign in

Spring Boot Cache Agent 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 to Spring Boot services, configuring cache expiration, evicting stale data, or diagnosing cache misses.

15k tokens
context cost
the whole folder, loaded on every use
5
files
instructions only
0
copies elsewhere
how many repositories repackaged it
316
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill spring-boot-cache

The instruction itself

14 sections, as written by the author

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

  • Add dependenciesspring-boot-starter-cache plus a provider:
  • Caffeine: caffeine starter
  • Redis: spring-boot-starter-data-redis
  • Ehcache: ehcache starter
  • Enable caching — annotate a @Configuration class with @EnableCaching

and define a CacheManager bean.

  • Annotate methods@Cacheable for reads, @CachePut for writes,

@CacheEvict for deletions.

  • Configure TTL/eviction — set spring.cache.caffeine.spec,

spring.cache.redis.time-to-live, or spring.cache.ehcache.config.

  • Shape keys — use SpEL in key attributes; guard with

condition/unless for selective caching.

  • 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 cached

Example 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.

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:

  • Verify @EnableCaching is present on a @Configuration class.
  • Confirm the method is public and called from outside the class (Spring uses

proxies; self-invocation bypasses the cache).

  • Validate SpEL key expressions resolve correctly.
  • Confirm the cache manager bean is registered as cacheManager or explicitly

referenced via cacheManager = "myCacheManager".

References

  • references/spring-framework-cache-docs.md:

curated excerpts from Spring Framework Reference Guide.

  • references/spring-cache-doc-snippet.md:

narrative overview from Spring documentation.

  • references/cache-core-reference.md:

annotation parameters, dependency matrices, property catalogs.

  • 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.
  • ../spring-boot-rest-api-standards
  • ../spring-boot-test-patterns
  • ../unit-test-caching

Other skills for the same job

different authors, same section of the catalogue
Fda Database
by christophacham
×4

Query openFDA API for drugs, devices, adverse events, recalls, regulatory submissions (510k, PMA), substance identification (UNII), for FDA regulatory data analysis and safety research.

32k tokens scripts
Alphafold Database
by christophacham
×3

Access AlphaFold 200M+ AI-predicted protein structures. Retrieve structures by UniProt ID, download PDB/mmCIF files, analyze confidence metrics (pLDDT, PAE), for drug discovery and structural biology.

7k tokens
Alphafold Database
by ComeOnOliver
×2

Access AlphaFold's 200M+ AI-predicted protein structures. Retrieve structures by UniProt ID, download PDB/mmCIF files, analyze confidence metrics (pLDDT, PAE), for drug discovery and structural biology.

9k tokens
Data Context Extractor
by anthropics
vendor ×1

> Generate or improve a company-specific data analysis skill by extracting tribal knowledge from analysts. "Help me create a skill for our database", "Generate a data skill for [company]" → Discovers schemas, asks key questions, generates initial skill with reference files "Update the data skill with [metrics/tables/terminology]", "Improve the [domain] reference" → Loads existing skill, asks targeted questions, appends/updates reference files Use when data analysts want Claude to understand their company's specific data warehouse, terminology, metrics definitions, and common query patterns.

7k tokens scripts
AgentDB Advanced Features
by Microck
×1

Master advanced AgentDB features including QUIC synchronization, multi-database management, custom distance metrics, hybrid search, and distributed systems integration. Use when building distributed AI systems, multi-agent coordination, or advanced vector search applications.

3k tokens
Geo Database
by BioTender-max
×1

NCBI GEO access via GEOparse and E-utilities. Search by keyword/organism/platform, download GSE series matrices, parse GPL annotations, extract GSM metadata, load expression matrices into pandas. For single-cell use cellxgene-census; for multi-DB access use gget-genomic-databases.

4k tokens
Advanced Agentdb Vector Search Implementation
by ComeOnOliver
×1

Master advanced AgentDB features including QUIC synchronization, multi-database management, custom distance metrics, and hybrid search for distributed AI systems.

29k tokens
Agentdb Advanced Features
by ComeOnOliver
×1

Master advanced AgentDB features including QUIC synchronization, multi-database management, custom distance metrics, hybrid search, and distributed systems integration. Use when building distributed AI systems, multi-agent coordination, or advanced vector search applications.

6k tokens

How to use it

Copy the folder

Take giuseppe-trisciuoglio/spring-boot-cache from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.