بنقرة واحدة
caching-patterns
Caching: Cache strategies, invalidation, TTL, CDN patterns, and performance optimization.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Caching: Cache strategies, invalidation, TTL, CDN patterns, and performance optimization.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Bun runtime: HTTP server, file I/O, SQLite, test runner, package manager, bundler — all-in-one JS toolchain.
Clerk: Drop-in auth UI, Organizations, User management, JWT templates, webhooks, Next.js middleware integration.
Gelişmiş masaüstü, tarayıcı ve işletim sistemi kontrol yeteneği. Görsel (koordinat tabanlı) fare/klavye otomasyonu, DOM manipülasyonu, pencere yönetimi, gelişmiş dosya, ağ ve süreç yönetimini kapsar.
Drizzle ORM: Schema definition, type-safe queries, migrations, relations, Postgres/SQLite/MySQL support.
Expo Router v3: File-based navigation, layouts, tabs, modals, deep linking, API routes, typed routes.
Flutter ile oyun geliştirme (Flame Engine vb.) ve karmaşık, büyük ölçekli mimariler kurma rehberi.
| name | caching-patterns |
| description | Caching: Cache strategies, invalidation, TTL, CDN patterns, and performance optimization. |
| triggers | {"extensions":[".ts"],"keywords":["cache","redis","TTL","invalidate","memoize","stale","revalidate"]} |
| auto_load_when | Implementing caching strategy |
| agent | infra-specialist |
| tools | ["Read","Write","Bash"] |
Focus: Performance, consistency, scalability
When to use each strategy:
├── Cache-aside (most common)
│ └── Flow: app checks cache → miss → fetch from DB → write cache
│ └── Use when: read-heavy, data changes infrequently
│ └── Risk: cache stampede (simultaneous misses)
│
├── Write-through
│ └── Flow: write to cache and DB simultaneously
│ └── Use when: data must be immediately consistent
│ └── Risk: write latency increase
│
├── Write-back
│ └── Flow: write to cache → async write to DB
│ └── Use when: write-heavy, can tolerate eventual consistency
│ └── Risk: data loss if cache fails before sync
│
└── Cache-first
└── Flow: check cache, fallback to DB only on miss
└── Use when: stale data acceptable
└── Risk: serving outdated data
When to use invalidation strategy:
├── Time-based (TTL)
│ └── Use when: eventual consistency acceptable
│ └── Set TTL based on data volatility
│ └── Simple, no need for complex invalidation
│
├── Event-based
│ └── Use when: need immediate consistency
│ └── Invalidate on write (Pub/Sub, cache invalidate message)
│ └── Complex but precise
│
├── Version-based
│ └── Use when: multiple versions of data
│ └── Key includes version: user:v2
│ └── On write, increment version and write new key
│
└── Manual
└── Use when: rare need to clear specific data
└── Admin endpoints for cache clearing
TTL guidelines:
├── Static content: 1 day to 1 week
├── User profile: 5-15 minutes
├── List queries: 30 seconds to 5 minutes
└── Search results: 1-5 minutes
When to use CDN:
├── Static assets
│ └── Images, CSS, JS, fonts
│ └── Cache at edge, long TTL
│ └── Serve close to user
│
├── API responses
│ └── Public, unpersonalized endpoints
│ └── Cache at edge with short TTL
│ └── Vary by Accept-Language, GeoIP
│
└── Not for CDN
└── Personalized data
└── Real-time data
└── Frequently changing content
Where to cache:
├── Client-side
│ ├── LocalStorage, SessionStorage
│ ├── Use when: data doesn't change often
│ ├── Cache-Control: max-age
│
├── CDN edge
│ ├── Use when: public, static content
│ ├── Cache-Control: s-maxage, public
│
├── API gateway
│ ├── Use when: multiple backend services
│ ├── Vary: headers, query params
│
├── Application (Redis/Memcached)
│ ├── Use when: shared across instances
│ ├── Session data, computed values
│
└── Database query cache
├── Use when: expensive queries
├── Query result caching
How to handle:
├── Cache stampede
│ ├── Problem: many requests hit DB simultaneously
│ ├── Solution: random jitter, request coalescing, locks
│
├── Thundering herd
│ ├── Problem: all requests retry at once after failure
│ ├── Solution: exponential backoff, circuit breaker
│
├── Cache penetration
│ ├── Problem: requests for non-existent keys
│ ├── Solution: cache null responses, bloom filters
│
└── Memory pressure
├── Problem: cache consumes too much memory
└── Solution: LRU eviction, max memory limits
❌ Caching mutable data without TTL
✅ Every cache entry has a TTL or explicit invalidation
❌ Cache stampede — all entries expire simultaneously
✅ Jitter on TTLs; probabilistic early expiration
❌ Caching at multiple layers with different stale states
✅ Define cache hierarchy: browser → CDN → app → DB query
❌ Not caching because "it's complex"
✅ Start with simple TTL caching; add complexity only if needed
❌ Sensitive data in shared caches
✅ User-specific data in private cache (no CDN); strip auth headers
| Layer | Tool | TTL guidance |
|---|---|---|
| Browser | Cache-Control, ETag | Static: 1y, HTML: no-cache |
| CDN | Cloudflare / Fastly | Vary on Accept-Encoding |
| App memory | node-cache / LRU | Short TTL, small hot set |
| Distributed | Redis | Session: 24h, API: 5-60s |
| DB query | Prisma + Redis | Heavy aggregations |
| Full-page | Next.js ISR | revalidate: 60 |