cache_patterns
БесплатноБез исполняемых скриптовНе проверенInstruction set for enabling and operating the Spring Cache abstraction in Spring Boot when implementing application-level caching for performance-sensitive…
Об этом скилле
Spring Boot Cache Abstraction
Overview
Spring Boot ships with a cache abstraction that wraps expensive service calls behind annotation-driven caches. This abstraction supports multiple cache providers (ConcurrentMap, Caffeine, Redis, Ehcache, JCache) without changing business code. The skill provides a concise workflow for enabling caching, managing cache lifecycles, and validating behavior in Spring Boot 3.5+ services.
When to Use
- Add
@Cacheable,@CachePut, or@CacheEvictto Spring Boot service methods. - Configure Caffeine, Redis, or JCache cache managers for Spring Boot.
- Diagnose cache invalidation, eviction scheduling, or cache key issues.
- Expose cache management endpoints or scheduled eviction routines.
Use trigger phrases such as "implement service caching", "configure CaffeineCacheManager", "evict caches on update", or "test Spring cache behavior" to load this skill.
Prerequisites
- Java 17+ project based on Spring Boot 3.5.x (records encouraged for DTOs).
- Dependency
spring-boot-starter-cache; add provider-specific starters as needed (spring-boot-starter-data-redis,caffeine,ehcache, etc.). - Constructor-injected services that expose deterministic method signatures.
- Observability stack (Actuator, Micrometer) when operating caches in production.
Quick Start
Add dependencies
<!-- Maven --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <dependency> <!-- Optional: Caffeine --> <groupId>com.github.ben-manes.caffeine</groupId> <artifactId>caffeine</artifactId> </dependency>implementation "org.springframework.boot:spring-boot-starter-cache" implementation "com.github.ben-manes.caffeine:caffeine"Enable caching
@Configuration @EnableCaching class CacheConfig { @Bean CacheManager cacheManager() { return new CaffeineCacheManager("users", "orders"); } }Annotate service methods
@Service @CacheConfig(cacheNames = "users") class UserService { @Cacheable(key = "#id", unless = "#result == null") User findUser(Long id) { ... } @CachePut(key = "#user.id") User refreshUser(User user) { ... } @CacheEvict(key = "#id", beforeInvocation = false) void deleteUser(Long id) { ... } }Verify behavior
- Run focused unit tests that call cached methods twice and assert repository invocations.
- Inspect Actuator
cacheendpoint (if enabled) for hit/miss counters.
🔄 Workflow
Kaynak: Spring Boot Caching Guide & Caffeine Cache Best Practices
Aşama 1: Strategy & Provider Selection
- Identifying Hot Paths: En çok beklenen ve nadir değişen veri okuma (I/O) noktalarını belirle.
- Provider Selection: Bellek içi (Caffeine) veya dağıtık (Redis) cache seçimine karar ver.
- Key Design: SpEL kullanarak benzersiz ve tahmin edilebilir cache key strategy'si oluştur.
Aşama 2: Annotation Implementation
- @Cacheable: Veriyi cache'e yaz we sonraki çağrılarda oradan oku.
- @CachePut: Veri güncellendiğinde cache'i de yenile.
- @CacheEvict: Silme işlemlerinde veya belirli periyotlarda cache'i temizle (
allEntries=trueopsiyonunu değerlendir).
Aşama 3: LifeCycle & Monitoring
- TTL/Eviction: Veri tazeliği (TTL) ve temizleme (Eviction) politikalarını (LRU/LFU) konfigüre et.
- Actuator Audit:
cacheendpoint'i üzerinden hit/miss oranlarını izle. - Integration Testing:
@SpringBootTestile cache izolasyonunu ve tutarlılığını test et.
Kontrol Noktaları
| Aşama | Doğrulama |
|---|---|
| 1 | Transactional işlemler sırasında cache tutarlılığı (Data drift) bozuluyor mu? |
| 2 | "Cache-aside" veya "ReadOnly" stratejisi doğru uygulandı mı? |
| 3 | Çoklu instance yapısında "Cache Stampede" riski önlendi mi? |
Cache Patterns v2.0 - With Workflow
Advanced Options
- Integrate JCache annotations when interoperating with providers that favor
JSR-107 (
@CacheResult,@CacheRemove). Avoid mixing with Spring annotations on the same method. - Cache reactive return types (
Mono,Flux) orCompletableFuturevalues. Spring stores resolved values and resubscribes on hits; consider TTL alignment with publisher semantics. - Apply HTTP caching headers using
CacheControlwhen exposing cached responses via REST.
Examples
- Load
references/cache-examples.mdfor progressive scenarios (basic product cache, conditional caching, multilevel eviction, Redis integration). - Load
references/cache-core-reference.mdfor annotation matrices, configuration tabl
Установить cache_patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteBashFAQ
Что делает скилл cache_patterns?
Instruction set for enabling and operating the Spring Cache abstraction in Spring Boot when implementing application-level caching for performance-sensitive workloads.
Как установить скилл cache_patterns?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл cache_patterns запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic