caching-strategies-knowledge

缓存策略知识库。汇集缓存模式(如缓存旁路、读穿透、写穿透、写回)、缓存失效策略、多级缓存方案,以及用于缓存审计和生成的 Redis 数据结构说明。

仓库最近推送
GitHub Stars
109
Forks
26
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "caching-strategies-knowledge":https://skillpi.com/zh/skills/deepskill-ca0f464cd1b8d4f42ecf9783944bba1a89e8898503fecc89af5fd039965f3a60。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

缓存策略知识库。汇集缓存模式(如缓存旁路、读穿透、写穿透、写回)、缓存失效策略、多级缓存方案,以及用于缓存审计和生成的 Redis 数据结构说明。

0 下载

介绍来源: third_party · dykyi-roman · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
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 consistency
  • references/redis-patterns.md — Eviction policies, data structure guide, cluster/sentinel, Lua scripting, PHP patterns
  • references/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

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值65/100

亮点

  • 提供全面的缓存策略知识库,涵盖多种缓存模式和失效策略
  • 包含 Redis 数据结构使用指南和实际应用场景
  • 适用于系统设计和性能优化参考
触发精准90/100

亮点

  • 触发词精准完整,覆盖缓存相关多种术语
  • description 清晰界定功能边界,避免歧义
结构规范85/100

待提升项

  • 缺少 When to Use 章节 原报告严重程度:轻微

    文档结构完整但缺少明确的使用场景说明章节

    改进建议:建议添加 'When to Use' 章节,说明何时使用此知识库

亮点

  • 结构清晰,分章节组织内容
  • 包含丰富的表格、流程图和代码示例
  • frontmatter 完整,格式规范
执行可靠95/100

亮点

  • 作为知识库无执行风险
  • 内容准确,参数和逻辑正确
  • Redis 数据结构描述准确完整
证据可验 (前四项均值)84/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。