Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

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.

Licencja
MIT
Ostatnia zmiana repozytorium
22.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
3
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 22.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

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

  1. Priority: P1 (HIGH)
  2. Caching Strategy
  3. NestJS Implementation
  4. Stampede Protection
  5. Redis Data Structures
  6. Invalidation Patterns
  7. Anti-Patterns
Sekcje z nagłówków SKILL.md, w oryginale · 45 linii, 245 słów
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.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.