application-caching

Designs server-side cache behavior for Spring Boot applications using Spring's cache abstraction.

39|3|Updated Jul 28, 2025
One-click install
npx skills add https://github.com/mzivkovicdev/spring-crud-generator --skill application-caching-mzivkovicdev
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: application-caching
Source: https://github.com/mzivkovicdev/spring-crud-generator/tree/main/.agents/skills/application-caching
Command: npx skills add https://github.com/mzivkovicdev/spring-crud-generator --skill application-caching-mzivkovicdev

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Adding a cache without clear rules produces stale data, cross-tenant leaks, and outages when the cache fails. This Skill provides correctness-first design rules for server-side caching in Java 21+ Spring Boot projects, covering staleness budgets, key identity, invalidation ordering, and failure handling. ## Core Features & Use Cases - Cache design rules: Defines the cache register, staleness budgets, TTL selection, key identity (tenant and subject), negative caching, stampede protection, and warmup strategy. - Invalidation and consistency: Enforces after-commit eviction, distributed invalidation across instances, namespace versioning for shape changes, and rolling-deploy safety. - Technology and topology guidance: Provides a property checklist for choosing local, distributed, or near-cache topologies (Caffeine, Redis, Hazelcast, and others) plus rules for the Hibernate second-level and query caches. - Use Case: When adding a @Cacheable product lookup to a multi-tenant Spring Boot service, use this Skill to derive the correct key, set a TTL within the staleness budget, and wire after-commit eviction instead of a transactional @CacheEvict. ## Quick Start Ask the AI to review or design a Spring Boot cache for a specific read path, including its key, TTL, and invalidation trigger.

Frequently Asked Questions about application-caching

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

FAQPage Schema
How do I add a cache to a Spring Boot service correctly?▼

Record a justification and staleness budget in a cache register, derive the key from every input that varies the value including the tenant, set a TTL at or below the budget, and cache immutable domain objects at the service boundary rather than entities.

Why is @CacheEvict on a @Transactional method wrong?▼

The eviction runs before the commit, so a concurrent reader can repopulate the cache with the pre-write row, leaving a permanently stale entry. Trigger invalidation after commit via a transactional event listener or a transaction-aware cache manager.

Should I use a local cache or Redis for Spring Boot caching?▼

Local caches like Caffeine suit small, slowly changing data with an approved staleness window. Distributed stores like Redis earn their network hop when entries must be consistent across instances, survive restarts, or are expensive to compute.

What should be in a Spring cache key for multi-tenant apps?▼

The key must contain every input that changes the result, including the tenant identifier and, when the value is filtered by authorization, the calling subject. Omitting the tenant serves one tenant's data to another.

When should I enable the Hibernate second-level cache?▼

Only after the project profile records a cache decision, with a staleness budget and a chosen concurrency strategy. The query cache is usually wrong because any write to touched tables invalidates it, giving a near-zero hit ratio on mutable data.

What are the limitations of caching in front of slow queries?▼

A cache never fixes an N+1 query, missing index, or unbounded read; it hides the defect and adds staleness. Fix the query first, then cache only with a structural or measured justification.