- Home
- Skills
- APIs & Backend
- Spring Boot cache strategy
Spring Boot cache strategy
Teach your coding agent to add caches that expire, invalidate after commit and keep working when the cache server is down.
Free
Works with the AI Agents you already use
Spring Boot cache strategy
Example session with this skill installed
Add a Redis cache to our article read endpoint. After an update, users must not keep seeing old data, and the API has to keep working if Redis goes down.
- Read your context and instructions
- Compiled the spring boot cache
Summary. Article reads are now cached through the framework's cache abstraction, with a declared Redis cache manager. Eviction happens only after commit, and every cache operation fails open. The full build passed twice in a row:
11 tests, 0 failures, 0 errors. No dependencies were added. The skill's "verify eviction is synchronous" step caught a real trap: for this provider, plain evict can run fire-and-forget, so failures would pass silently. The code uses evictIfPresent, which runs synchronously and reports failures.
| Cache | Key | Value | TTL | Serializer | Evicted by | Timing | On store error |
|---|---|---|---|---|---|---|---|
| article | cache:v1:article:<id> | Immutable ArticleView DTO | 10 min (assumed staleness limit) | JSON bound to ArticleView, no type metadata | PUT, DELETE | After commit | Counted, falls back to the database |
Command and connect timeouts are 500 ms; the latency budget during an outage is 2 s.
Verified by tests against real Redis and PostgreSQL in containers:
- The key, a TTL above 0 and at most 600 s, and the plain JSON format are read directly from Redis; a hit returns an
ArticleView. - A value changed directly in the database is still served from the cache; not-found results are not cached.
- Eviction removes only the target key; other entries, other caches and
lock:keys survive. - A parameterized test proves that PUT and DELETE both evict; the key is still present inside the transaction and gone after commit; a rollback evicts nothing.
- An undeclared cache cannot be created.
- Hit and miss counts show on the metrics endpoint.
- With Redis paused, GET and PUT succeed from the database within 2 s, error counters rise, the eviction-failure counter rises by exactly 1, and probes stay at 200.
Next steps. Confirm the real staleness limit and set the TTL to match. Alert on the eviction-failure counter. Add a lock fail-closed test if you put locks in the same Redis.
Connects securely to your tools. The creator never sees your data.
About this skill
A cache is easy to add and easy to get wrong. Entries never expire, eviction runs before the transaction commits so old data is cached again, entries use native object serialization, or a cache server outage takes every request down with it.
This skill gives Claude Code, Cursor, Codex CLI and other SKILL.md-compatible agents a version-agnostic workflow for caching. Before writing code, the agent reads the build file and records the actual framework, cache provider and client versions. It verifies how the detected provider evicts and confirms every API for those versions. Then it fills a cache inventory and checks every write path that affects a cached value.
The guidance covers what is worth caching, JSON serialization bound to the cached type, a TTL on every entry, and namespaced keys built in one place. Eviction targets exact keys, runs after the transaction commits, and uses an operation that reports failures. Reads and writes fail open and are counted during an outage, while locks in the same store fail closed. It also covers hit and miss metrics and keeping the cache store out of health probes. A test plan reads entries directly from a real store and pauses it to prove the outage behaviour.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.
Requires Testcontainers or a real store for full verification. Supports Spring-based stacks only. Does not support pattern-based bulk eviction.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free to use
No account required to browse
Trust & safety
Security scan
Security scan passed 2 days ago
- Free with an Agensi account
- Software
- Spring Boot projectMavenorGradle
Docker (for Testcontainers)
- Optional
- Redisoranother cache store
Integration tests use Testcontainers, so Docker must be running. On Windows, use Docker Desktop.
Permissions
File Scopes
Reads build files and source code to detect versions and assess the existing code, writes code and tests in the project, and runs the build and tests from the terminal. The build tool and Testcontainers may download dependencies and container images. No external accounts, API keys or credentials are needed.