nestjs-caching
/nestjs-caching
Wdraża wielopoziomowe cache, wzorce unieważniania i ochronę przed stampede w NestJS z Redis, cache-manager i stale-while-revalidate.
- Autor
- HoangNguyen0403 ↗
- Repozytorium
- agent-skills-standard ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 22.10.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 3
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 22.10.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Wdraża wielopoziomowe cache, wzorce unieważniania i ochronę przed stampede w NestJS z Redis, cache-manager i stale-while-revalidate.
Oryginalny opis (EN)
Implement multi-level caching, invalidation patterns, and stampede protection in NestJS. Use when adding Redis caching layers, configuring cache-manager interceptors, implementing stale-while-revalidate, or preventing cache stampedes in NestJS services.
Jak działa
- Priority: P1 (HIGH)
- Caching Strategy
- NestJS Implementation
- Stampede Protection
- Redis Data Structures
- Invalidation Patterns
- Anti-Patterns
Podgląd SKILL.md
---
name: nestjs-caching
description: Implement multi-level caching, invalidation patterns, and stampede protection in NestJS. Use when adding Redis caching layers, configuring cache-manager interceptors, implementing stale-while-revalidate, or preventing cache stampedes in NestJS services.
metadata:
triggers:
files:
- '**/*.service.ts'
- '**/*.interceptor.ts'
keywords:
- CacheInterceptor
- CacheTTL
- Redis
- stale-while-revalidate
---
# Caching & Redis Standards
## **Priority: P1 (HIGH)**
## Caching Strategy
- **Layering**: Use **Multi-Level Caching** for high-traffic read endpoints.
- **L1 (Local)**: In-Memory (Node.js heap). Ultra-fast, no network. Use `lru-cache` for config/static data.
- **L2 (Distributed)**: Redis. Shared across pods.
- **Pattern**: Implement **Stale-While-Revalidate** to avoid latency spikes during cache misses.
## NestJS Implementation
- **Library**: Use `cache-manager` with `cache-manager-redis-yet` (recommended over `cache-manager-redis-store` for V4 stability).
- **Interceptors**: Use `@UseInterceptors(CacheInterceptor)` for simple GET responses.
- **Warning**: Default key URL. Ensure consistent query param ordering or use custom key generators.
See [implementation examples](references/example.md)
## Stampede Protection
- **Jitter**: Add random variance to TTLs to prevent simultaneous expiry across keys.
- **Locking**: One process recomputes while others wait or return stale data.
See [implementation examples](references/example.md)
## Redis Data Structures
- **Hash (`HSET`)**: Store objects (user profiles) with partial update support.
- **Set (`SADD`)**: Unique collections with O(1) membership checks.
- **Sorted Set (`ZADD`)**: Priority queues, leaderboards, rate-limiting windows.
## Invalidation Patterns
- **Tagging**: Use Sets to group cache keys (avoid `KEYS` which O(N) in production).
- _Create_: `SADD post:1:tags cache:post:1`
- _Invalidate_: Fetch tags from Set, then `DEL` grouped keys.
- **Event-Driven**: Listen to domain events (`UserUpdated`) to trigger invalidation asynchronously.
## Anti-Patterns
- **No KEYS in production**: Use SET-based tag grouping for cache invalidation; KEYS O(N).
- **No fixed TTLs on grouped caches**: Add jitter (±10s) to prevent simultaneous stampede.
- **No MemoryStorage for multi-pod**: Use Redis store; in-memory cache not shared across pods.
Pliki w paczce (3)
- SKILL.md 2 KB
- evals/evals.json 2 KB
- references/example.md 1 KB
Wersje
W bazie nie ma innych skilli o nazwie nestjs-caching.
Migawka bazy z 13.11.2026 · wersja paczki 31fa78f51b55 (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 1 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100caching-strategies
Projektuje wielowarstwowe architektury cache dla aplikacji webowych: wzorce cache-aside i write-through, TTL, unieważnianie, Redis, CDN, nagłówki Cache-Control i ochrona przed stampede. - 100caching-strategies
Opisuje wzorce cache w aplikacjach: Redis, cache w pamięci, cache HTTP, CDN, unieważnianie, cache-aside, write-through i stale-while-revalidate. - 90caching-strategy
Wdraża wzorce Redis i Memcached oraz strategie unieważniania cache w aplikacji. - 100caching
Pomaga dodać lub zdiagnozować cache: umiejscowienie, unieważnianie, ochrona przed stampede, dobór TTL i świadomość kompromisu w spójności danych. - 100caching
Pomaga dodawać i debugować cache w usłudze: dobór strategii, projektowanie TTL, ochrona przed stampede, unieważnianie oraz konfiguracja nagłówków HTTP Cache-Control. - 100caching
Pomaga dodawać i debugować cache w usłudze: dobór strategii, projektowanie TTL, ochrona przed stampede, unieważnianie oraz konfiguracja nagłówków HTTP Cache-Control.