← 返回 Skills 市场
wpank

caching

作者 wpank · GitHub ↗ · v1.0.0
cross-platform ✓ 安全检测通过
1040
总下载
0
收藏
9
当前安装
1
版本数
在 OpenClaw 中安装
/install caching
功能描述
Caching strategies, invalidation, eviction policies, HTTP caching, distributed caching, and anti-patterns. Use when designing cache layers, choosing eviction policies, debugging stale data, or optimizing read-heavy workloads.
使用说明 (SKILL.md)

Caching Patterns

A well-placed cache is the cheapest way to buy speed. A misplaced cache is the most expensive way to buy bugs.

Cache Strategies

Strategy How It Works When to Use
Cache-Aside (Lazy) App checks cache → miss → reads DB → writes to cache Default choice — general purpose
Read-Through Cache fetches from DB on miss automatically ORM-integrated caching, CDN origin fetch
Write-Through Writes go to cache AND DB synchronously Read-heavy with strong consistency
Write-Behind Writes go to cache, async flush to DB High write throughput, eventual consistency OK
Refresh-Ahead Cache proactively refreshes before expiry Predictable access patterns, low-latency critical
Cache-Aside Flow:

  App ──► Cache ──► HIT? ──► Return data
              │
              ▼ MISS
          Read DB ──► Store in Cache ──► Return data

Cache Invalidation

Method Consistency When to Use
TTL-based Eventual (up to TTL) Simple data, acceptable staleness
Event-based Strong (near real-time) Inventory, profile updates
Version-based Strong Static assets, API responses, config
Tag-based Strong CMS content, category-based purging

TTL Guidelines

Data Type TTL Rationale
Static assets (CSS/JS/images) 1 year + cache-busting hash Immutable by filename
API config / feature flags 30–60 seconds Fast propagation needed
User profile data 5–15 minutes Tolerable staleness
Product catalog 1–5 minutes Balance freshness vs load
Session data Match session timeout Security requirement

HTTP Caching

Cache-Control Directives

Directive Meaning
max-age=N Cache for N seconds
s-maxage=N CDN/shared cache max age (overrides max-age)
no-cache Must revalidate before using cached copy
no-store Never cache anywhere
must-revalidate Once stale, must revalidate
private Only browser can cache, not CDN
public Any cache can store
immutable Content will never change (within max-age)
stale-while-revalidate=N Serve stale for N seconds while fetching fresh

Common Recipes

# Immutable static assets (hashed filenames)
Cache-Control: public, max-age=31536000, immutable

# API response, CDN-cached, background refresh
Cache-Control: public, s-maxage=60, stale-while-revalidate=300

# Personalized data, browser-only
Cache-Control: private, max-age=0, must-revalidate
ETag: "abc123"

# Never cache (auth tokens, sensitive data)
Cache-Control: no-store

Conditional Requests

Mechanism Request Header Response Header How It Works
ETag If-None-Match: "abc" ETag: "abc" Hash-based — 304 if match
Last-Modified If-Modified-Since: \x3Cdate> Last-Modified: \x3Cdate> Date-based — 304 if unchanged

Prefer ETag over Last-Modified — ETags detect content changes regardless of timestamp granularity.


Application Caching

Solution Speed Shared Across Processes When to Use
In-memory LRU Fastest No Single-process, bounded memory, hot data
Redis Sub-ms (network) Yes Production default — TTL, pub/sub, persistence
Memcached Sub-ms (network) Yes Simple key-value at extreme scale
SQLite Fast (disk) No Embedded apps, edge caching

Redis vs Memcached

Feature Redis Memcached
Data structures Strings, hashes, lists, sets, sorted sets Strings only
Persistence AOF, RDB snapshots None
Pub/Sub Yes No
Max value size 512 MB 1 MB
Verdict Default choice Pure cache at extreme scale

Distributed Caching

Concern Solution
Partitioning Consistent hashing — minimal reshuffling on node changes
Replication Primary-replica — writes to primary, reads from replicas
Failover Redis Sentinel or Cluster auto-failover

Rule of thumb: 3 primaries + 3 replicas minimum for production Redis Cluster.


Cache Eviction Policies

Policy How It Works When to Use
LRU Evicts least recently accessed Default — general purpose
LFU Evicts least frequently accessed Skewed popularity distributions
FIFO Evicts oldest entry Simple, time-ordered data
TTL Evicts after fixed duration Data with known freshness window

Redis default is noeviction. Set maxmemory-policy to allkeys-lru or volatile-lru for production.


Caching Layers

Browser Cache → CDN → Load Balancer → App Cache → DB Cache → Database
Layer What to Cache Invalidation
Browser Static assets, API responses Versioned URLs, Cache-Control
CDN Static files, public API responses Purge API, surrogate keys
Application Computed results, DB queries, external API Event-driven, TTL
Database Query plans, buffer pool, materialized views ANALYZE, manual refresh

Cache Stampede Prevention

When a hot key expires, hundreds of requests simultaneously hit the database.

Technique How It Works
Mutex / Lock First request locks, fetches, populates; others wait
Probabilistic early expiration Random chance of refreshing before TTL
Request coalescing Deduplicate in-flight requests for same key
Stale-while-revalidate Serve stale, refresh asynchronously

Cache Warming

Strategy When to Use
On-deploy warm-up Predictable key set, latency-sensitive
Background job Reports, dashboards, catalog data
Shadow traffic Cache migration, new infrastructure
Priority-based Limited warm-up time budget

Cold start impact: A full cache flush can increase DB load 10–100x. Always warm gradually or use stale-while-revalidate.


Monitoring

Metric Healthy Range Action if Unhealthy
Hit rate > 90% Low → cache too small, wrong TTL, bad key design
Eviction rate Near 0 steady state High → increase memory or tune policy
Latency (p99) \x3C 1ms (Redis) High → network issue, large values, hot key
Memory usage \x3C 80% of max Approaching max → scale up or tune eviction

NEVER Do

  1. NEVER cache without a TTL or invalidation plan — data rots; every entry needs an expiry path
  2. NEVER treat cache as durable storage — caches evict, crash, and restart; always fall back to source of truth
  3. NEVER cache sensitive data (tokens, PII) without encryption — cache breaches expose everything in plaintext
  4. NEVER ignore cache stampede on hot keys — one expired popular key can take down your database
  5. NEVER use unbounded in-memory caches in production — memory grows until OOM-killed
  6. NEVER cache mutable data with immutable Cache-Control — browsers will never re-fetch
  7. NEVER skip monitoring hit/miss rates — you won't know if your cache is helping or hurting
安全使用建议
This skill is a documentation/reference skill about caching and appears internally consistent. Before installing, verify the skill source (there's no homepage and the owner ID is opaque). Do not run unfamiliar install commands you find in README (especially ad-hoc npx commands pointing at arbitrary GitHub paths). If you want the content, prefer reviewing SKILL.md/README locally or copying the text rather than executing remote install scripts. If you plan to add code from an external repo, inspect the repository contents first. Overall risk is low for this instruction-only skill, but always avoid providing secrets or running unreviewed installs.
功能分析
Type: OpenClaw Skill Name: caching Version: 1.0.0 The skill bundle provides comprehensive documentation on caching strategies and related concepts. Neither SKILL.md nor README.md contain any prompt injection attempts against the AI agent, malicious execution commands, data exfiltration, persistence mechanisms, or obfuscation. The installation instructions in README.md use standard package managers (`npx add`) and file copy commands (`cp -r`) to install the skill itself, which is a common and benign practice for skill distribution.
能力评估
Purpose & Capability
The skill is purely documentation about caching strategies, HTTP caching, eviction policies, distributed caching, and anti-patterns. It requests no binaries, env vars, or config paths — all of which align with a knowledge/guide-style skill.
Instruction Scope
SKILL.md contains explanatory guidance, recipes, and examples for caching behavior. It does not instruct the agent to read unrelated system files, access credentials, or send data to external endpoints.
Install Mechanism
There is no formal install spec (instruction-only), which is low risk. The README contains an example 'npx add https://github.com/…/tree/…' command that is non-standard (GitHub tree URL) — it's an odd or potentially invalid usage of npx rather than a tracked package install. This is a documentation oddity rather than executable install metadata in the skill itself; avoid running ad-hoc install commands from unknown URLs.
Credentials
The skill requests no environment variables, credentials, or config paths. That is proportionate for a read-only documentation skill.
Persistence & Privilege
always is false and the skill is instruction-only with no code to persist or run on install. It does not request elevated or persistent platform privileges.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install caching
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /caching 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release of the caching skill. - Covers core caching strategies: cache-aside, read-through, write-through, write-behind, refresh-ahead. - Details cache invalidation methods, TTL guidelines, and HTTP caching best practices. - Summarizes common application caching solutions: in-memory, Redis, Memcached, SQLite. - Explains distributed cache concepts, eviction policies, and cache layer design. - Includes anti-patterns, stampede prevention, cache warming, and monitoring recommendations.
元数据
Slug caching
版本 1.0.0
许可证
累计安装 9
当前安装数 9
历史版本数 1
常见问题

caching 是什么?

Caching strategies, invalidation, eviction policies, HTTP caching, distributed caching, and anti-patterns. Use when designing cache layers, choosing eviction policies, debugging stale data, or optimizing read-heavy workloads. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 1040 次。

如何安装 caching?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install caching」即可一键安装,无需额外配置。

caching 是免费的吗?

是的,caching 完全免费(开源免费),可自由下载、安装和使用。

caching 支持哪些平台?

caching 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 caching?

由 wpank(@wpank)开发并维护,当前版本 v1.0.0。

💬 留言讨论