Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

cache-management

БесплатноБез исполняемых скриптовНе проверен

Implement production-grade caching with cache keys/TTLs/consistency classes per query, SWR (stale-while-revalidate), explicit invalidation, HTTP cache…

VilnaCRM-Orgот VilnaCRM-Org★ 16 звёзд на GitHub

Об этом скилле

Cache Management Skill

Context (Input)

Use this skill when:

  • Adding caching to repositories or expensive queries
  • Implementing cache invalidation via domain events
  • Defining cache keys, TTLs, and consistency requirements
  • Implementing stale-while-revalidate (SWR) pattern
  • Configuring HTTP cache headers (Cache-Control, ETag, Vary)
  • Testing cache behavior (stale reads, cold start, invalidation)
  • Reducing database load with caching
  • Setting up async event-driven cache invalidation

Task (Function)

Implement production-ready caching with proper key design, TTL management, event-driven invalidation, HTTP cache headers, and comprehensive testing.

Success Criteria:

  • Cache policy declared for each query (key, TTL, consistency class)
  • Decorator pattern with CachedXxxRepository wrapping MongoXxxRepository
  • Event-driven invalidation via domain event subscribers
  • Marker interface pattern for auto-binding cache pools
  • Best-effort invalidation (try/catch, never fail business operations)
  • HTTP cache headers configured (Cache-Control, ETag for API responses)
  • Async event processing via message queue (AP from CAP theorem)
  • Comprehensive unit tests for all cache paths
  • Cache observability (hit/miss/error logging)
  • make ci outputs "✅ CI checks successfully passed!"

⚠️ CRITICAL CACHE POLICY

╔═══════════════════════════════════════════════════════════════╗
║  ALWAYS use Decorator Pattern for caching (wrap repositories) ║
║  ALWAYS use CacheKeyBuilder service (prevent key drift)       ║
║  ALWAYS invalidate via Domain Events (decouple from business) ║
║  ALWAYS use TagAwareCacheInterface for cache tags             ║
║  ALWAYS wrap cache ops in try/catch (best-effort, no failures)║
║  ALWAYS use Marker Interface for auto-binding cache pools     ║
║  ALWAYS process invalidation async (AP from CAP theorem)      ║
║                                                               ║
║  ❌ FORBIDDEN: Caching in repository, implicit invalidation   ║
║  ✅ REQUIRED:  Decorator pattern, event-driven invalidation   ║
╚═══════════════════════════════════════════════════════════════╝

CAP Theorem: Why We Choose AP (Availability + Partition Tolerance)

Cache invalidation follows AP from CAP theorem - we prioritize:

  • Availability: Business operations never fail due to cache issues
  • Partition Tolerance: System works even when cache is unavailable

Trade-off: Brief staleness is acceptable over blocking writes.

Implementation:

  • Cache errors fallback to database (try/catch everywhere)
  • Invalidation processed asynchronously via message queue
  • Exceptions in subscribers are logged + emit metrics (self-healing)
  • Business operations complete even if cache invalidation fails

Non-negotiable requirements:

  • Use Decorator Pattern: CachedXxxRepository wraps MongoXxxRepository
  • Use centralized CacheKeyBuilder service (in Shared/Infrastructure/Cache)
  • Invalidate via Domain Event Subscribers (one subscriber per event)
  • Use Marker Interface for auto-binding cache pools via _instanceof
  • Process cache invalidation asynchronously via message queue
  • Wrap ALL cache operations in try/catch (never fail business operations)
  • Use TagAwareCacheInterface (not CacheInterface) for tag support
  • Configure test cache pools with tags: true in config/packages/test/cache.yaml
  • Log cache operations for observability

File Locations (This Codebase)

These are example locations based on the Codely/Hexagonal structure used in VilnaCRM services. Adapt the bounded context (User, OAuth, etc.) to your feature.

Component Typical Location
CacheKeyBuilder src/Shared/Infrastructure/Cache/CacheKeyBuilder.php
CachedXxxRepository src/{Context}/{Bounded}/Infrastructure/Repository/CachedXxxRepository.php
Base repository (inner) src/{Context}/{Bounded}/Infrastructure/Repository/*Repository.php
Marker interface src/{Context}/{Bounded}/Application/EventSubscriber/*CacheInvalidationSubscriberInterface.php
Invalidation subscriber src/{Context}/{Bounded}/Application/EventSubscriber/*CacheInvalidationSubscriber.php
Cache pool config config/packages/cache.yaml
Test cache config config/packages/test/cache.yaml
Service wiring / aliases config/services.yaml
HTTP cache tests `tests/Integration/*Htt
Полный SKILL.md на GitHub

Установить cache-management в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

examples/cache-implementation.mdexamples/cache-testing.mdreference/cache-policies.mdreference/invalidation-strategies.mdreference/swr-pattern.md

FAQ

Что делает скилл cache-management?

Implement production-grade caching with cache keys/TTLs/consistency classes per query, SWR (stale-while-revalidate), explicit invalidation, HTTP cache headers, and comprehensive testing for stale reads and cache warmup. Use when adding caching to queries, implementing cache invalidation, configuring HTTP caching, or ensuring cache consistency and performance.

Как установить скилл cache-management?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл cache-management запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить cache-management с