caching-strategies-knowledge
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "caching-strategies-knowledge" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-ca0f464cd1b8d4f42ecf9783944bba1a89e8898503fecc89af5fd039965f3a60. Verify the upstream source and version against https://github.com/dykyi-roman/awesome-claude-code before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Caching strategies knowledge base. Collects caching patterns (such as cache bypass, read-through, write-through, write-back), cache invalidation strategies, multi-level caching approaches, and descriptions of Redis data structures used for cache auditing and generation.
Introduction source: third_party · dykyi-roman · 0.0.1 Reference
SkillPi interpretation
- Tasks
- Caching Strategies knowledge base. Provides caching patterns (Cache-Aside, Read-Through, Write-Through, Write-Behind), invalidation approaches, multi-level caching, and Redis data structures for caching audits and generation.
- Testing
- Not tested
Browse files
Frontmatter
name: caching-strategies-knowledge
description: Caching Strategies knowledge base. Provides caching patterns (Cache-Aside, Read-Through, Write-Through, Write-Behind), invalidation approaches, multi-level caching, and Redis data structures for caching audits and generation.Caching Strategies Knowledge Base
Quick reference for caching patterns, invalidation strategies, and Redis implementation guidelines. Focuses on caching theory and Redis patterns — for Cache-Aside code generation, see create-cache-aside.
Caching Strategies
| Strategy | How It Works | Consistency | Performance | Use Case |
|---|---|---|---|---|
| Cache-Aside | App reads cache first, fetches from DB on miss, writes to cache | Eventual | Read-heavy | General purpose, most common |
| Read-Through | Cache itself fetches from DB on miss | Eventual | Read-heavy | Transparent caching layer |
| Write-Through | App writes to cache and DB synchronously | Strong | Write-heavy (slower writes) | Consistency-critical data |
| Write-Behind | App writes to cache, cache writes to DB asynchronously | Eventual | Write-heavy (fast writes) | High write throughput |
| Write-Around | App writes directly to DB, cache populated on read | Eventual | Infrequent-read data | Write-once, read-later |
Strategy Flow Diagrams
Cache-Aside (Lazy Loading):
Read: App → Cache (hit?) → yes → return
→ no → DB → write to Cache → return
Write: App → DB → invalidate Cache
Read-Through:
Read: App → Cache (hit?) → yes → return
→ no → Cache fetches from DB → return
Write: App → DB → invalidate Cache
Write-Through:
Read: App → Cache (hit?) → yes → return
→ no → DB → return
Write: App → Cache → Cache writes to DB (sync)
Write-Behind (Write-Back):
Read: App → Cache (hit?) → yes → return
→ no → DB → return
Write: App → Cache → Cache writes to DB (async, batched)
Cache Invalidation Approaches
| Approach | Description | Consistency | Complexity |
|---|---|---|---|
| TTL (Time-To-Live) | Cache expires after fixed duration | Eventual (stale window) | Low |
| Event-Driven | Invalidate on domain event | Near real-time | Medium |
| Versioned Keys | Include version in cache key | Immediate (new key) | Medium |
| Tag-Based | Group related keys by tag, purge by tag | Immediate | High |
| Write-Through | Update cache on write | Immediate | Medium |
| Manual | Explicit invalidation in code | Depends on discipline | Low |
TTL Selection Guide
| Data Type | TTL | Reasoning |
|---|---|---|
| Static config | 1-24 hours | Rarely changes |
| User profile | 5-15 minutes | Moderate change frequency |
| Session data | 30 minutes | Linked to session timeout |
| Product catalog | 1-5 minutes | Moderate updates |
| Search results | 30-60 seconds | Frequent updates |
| Real-time data | 5-15 seconds | High change frequency |
| Counters/stats | No TTL (event-driven) | Update on write |
Multi-Level Caching
┌─────────────────────────────────────────────────┐
│ MULTI-LEVEL CACHE │
│ │
│ Request → L1 (In-Process) hit → return │
│ miss ↓ │
│ L2 (Redis/Memcached) hit → populate L1 │
│ miss ↓ │
│ L3 (CDN/HTTP Cache) hit → populate L2 │
│ miss ↓ │
│ Database → populate L2 → populate L1 │
└─────────────────────────────────────────────────┘
| Level | Storage | Latency | Capacity | Scope |
|---|---|---|---|---|
| L1 | In-process (APCu, static) | < 1μs | Small (MB) | Per-process |
| L2 | Distributed (Redis) | 1-5ms | Large (GB) | Shared |
| L3 | CDN / HTTP Cache | 5-50ms | Very large | Global |
| Origin | Database | 10-100ms | Unlimited | Source of truth |
Redis Data Structures for Caching
| Structure | When to Use | Example |
|---|---|---|
| String | Simple key-value, serialized objects | User session, JSON blob |
| Hash | Object with fields, partial reads | User profile (name, email, role) |
| Sorted Set | Ranked data, leaderboards, time-series | Top products, recent activity |
| List | Queues, recent items, feeds | Recent notifications |
| Set | Unique collections, tags | User permissions, online users |
| HyperLogLog | Cardinality estimation | Unique visitors count |
Strategy Selection by Workload
| Workload | Strategy | Why |
|---|---|---|
| Read-heavy, tolerance for stale | Cache-Aside + TTL | Simple, effective |
| Read-heavy, consistency needed | Cache-Aside + event invalidation | Fresh data |
| Write-heavy, read-after-write | Write-Through | Immediate consistency |
| Write-heavy, async OK | Write-Behind | Best write performance |
| Mixed, complex invalidation | Tag-based + event-driven | Granular control |
| API responses | HTTP Cache (CDN) + L2 | Reduce server load |
Detection Patterns
# Cache usage
Grep: "Cache|Redis|Memcached|APCu|apc_" --glob "**/*.php"
Grep: "CacheInterface|CacheItemPoolInterface|SimpleCacheInterface" --glob "**/*.php"
# Cache-Aside pattern
Grep: "->get\(.*\).*->set\(" --glob "**/*.php"
Grep: "cache->has|cache->get|cache->set" --glob "**/*.php"
# TTL configuration
Grep: "ttl|expire|setex|SETEX|TTL" --glob "**/*.php"
Grep: "CACHE_TTL|CACHE_LIFETIME" --glob "**/.env*"
# Cache invalidation
Grep: "->delete\(|->invalidate\(|->clear\(|->flush\(" --glob "**/*.php"
Grep: "invalidateTag|invalidateTags|clearByTag" --glob "**/*.php"
# Redis patterns
Grep: "Predis|PhpRedis|Redis::|new Redis" --glob "**/*.php"
Grep: "REDIS_HOST|REDIS_URL" --glob "**/.env*"
# Multi-level caching
Grep: "ChainCache|StackedCache|MultiLevelCache" --glob "**/*.php"
Grep: "apcu_fetch|apcu_store" --glob "**/*.php"
Advanced Patterns
Cache Stampede Prevention
| Method | How It Works | Complexity | Best For |
|---|---|---|---|
| Locking (Mutex) | One process recomputes, others wait | Medium | Most cases |
| Probabilistic Early Expiry (XFetch) | Recompute before TTL with probability | Medium | High concurrency |
| Stale-While-Revalidate | Serve stale, refresh async | Medium | Latency-critical |
| External refresh | Cron/worker refreshes before expiry | Low | Predictable access |
Distributed Cache Coherence
| Strategy | Consistency | Latency | Complexity |
|---|---|---|---|
| TTL only | Eventual (stale window) | None | Low |
| Pub/Sub invalidation | Near-real-time | ~1-5ms | Medium |
| Write-through all nodes | Strong | High | High |
| Version-based (ETag) | Strong (on read) | Per-read check | Medium |
Write-Back vs Write-Through
| Aspect | Write-Through | Write-Back |
|---|---|---|
| Write latency | Higher (sync) | Lower (cache only) |
| Data safety | Safe | Risk of loss |
| Consistency | Strong | Eventual |
| DB load | Per-write | Batched |
| Use case | Financial, orders | Analytics, counters |
References
For detailed information, load these reference files:
references/strategies.md— Detailed strategy analysis, cache warming, stampede prevention, distributed consistencyreferences/redis-patterns.md— Eviction policies, data structure guide, cluster/sentinel, Lua scripting, PHP patternsreferences/advanced-patterns.md— Cache stampede prevention (locking, XFetch, stale-while-revalidate), cache warming strategies, write-back vs write-through comparison, distributed cache coherence, key design patterns
Current listing version
0.0.1
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供全面的缓存策略知识库,涵盖多种缓存模式和失效策略
- 包含 Redis 数据结构使用指南和实际应用场景
- 适用于系统设计和性能优化参考
Highlights
- 触发词精准完整,覆盖缓存相关多种术语
- description 清晰界定功能边界,避免歧义
Areas to improve
-
缺少 When to Use 章节 Reported severity: Minor
文档结构完整但缺少明确的使用场景说明章节
Recommendation: 建议添加 'When to Use' 章节,说明何时使用此知识库
Highlights
- 结构清晰,分章节组织内容
- 包含丰富的表格、流程图和代码示例
- frontmatter 完整,格式规范
Highlights
- 作为知识库无执行风险
- 内容准确,参数和逻辑正确
- Redis 数据结构描述准确完整
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.