cache-engineering

cache-engineering is a skill for Claude Code, Codex from chaunsin/agent-skills. It costs 99 tokens per session (3,057 once invoked), scanned A, original, Apache-2.0.

A set of engineering guidelines for designing and reviewing caches such as Redis, Memcached, in-process caches, and multi-level caches. A cache is a temporary copy of data kept for faster reads.

In plain words
What is it for?
Use it to choose cache keys and expiry times, review cache-aside flows, handle rebuilds and invalidation, and plan fallback behavior for Redis or other caches.
Why use it?
It helps avoid stale data, missing invalidations, cache stampedes, and unsafe use of cached values for decisions such as payments or inventory. It provides a default read and write approach while accounting for failures and concurrency.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to choose cache keys and expiry times, review cache-aside flows, handle rebuilds and invalidation, and plan fallback behavior for Redis or other caches.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/chaunsin/agent-skills/cache-engineering
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add chaunsin/agent-skills --skill cache-engineering
Clone the repo
git clone --depth 1 https://github.com/chaunsin/agent-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for cache-engineering

README.md
[![agentmods](https://agentmods.dev/badge/skills/chaunsin/agent-skills/cache-engineering/github.svg)](https://agentmods.dev/skills/chaunsin/agent-skills/cache-engineering)
Your own site
<a href="https://agentmods.dev/skills/chaunsin/agent-skills/cache-engineering"><img src="https://agentmods.dev/badge/skills/chaunsin/agent-skills/cache-engineering/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for cache-engineering

Your own site · 80×15
<a href="https://agentmods.dev/skills/chaunsin/agent-skills/cache-engineering"><img src="https://agentmods.dev/badge/skills/chaunsin/agent-skills/cache-engineering.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 99 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,057 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00099 $0.03057
Opus 5.5 $0.00040 $0.01223
Sonnet 5.5 $0.00020 $0.00611
Haiku 4.5 $0.00010 $0.00306

Measured 13d ago against content hash 4e28e4ae8ec2, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

cache-engineering scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 13d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/cache-engineering/SKILL.md · 158 lines

How it starts

The opening of the file, as written. The whole thing — 158 lines — stays where its author put it; the contents beside it link to each section on GitHub.

缓存工程实践

一、适用范围与默认决策

适用于可丢弃、可从权威数据源重建的业务缓存,不依赖特定语言或 Agent 平台。Redis 也可承载持久业务状态;不能仅因使用 Redis 就将其按缓存删除或降级处理。

默认采用 Cache-Aside(旁路缓存):读取未命中时回源,写入时先提交数据库事务,再删除受影响缓存,后续读取被动重建。以下用“数据库”代表权威数据源。

  • 默认方案允许短暂不一致;先明确允许旧数据的范围和时长,再选择增强机制。
  • 不默认先写缓存再写数据库,也不默认主动更新缓存。已有读穿、写穿或预热方案应依据其一致性和失败处理评审,不仅为统一模式而重写。
  • 业务正确性优先;余额扣减、库存扣减、权限撤销等关键决策不能仅凭可能过期的缓存结果完成。

二、执行流程

  1. 检查现状:先读相关代码、配置和已有约定,识别权威数据源、事务边界、所有写入入口及现有失效机制。
  2. 补齐决策条件:确认新鲜度要求、读写量与热点、缓存产品及版本、单机或集群、本地缓存、租户隔离和已有基础设施。只追问会改变方案的缺失信息,其余标注假设并继续可独立完成的工作。
  3. 设计或审查:按下文确定读写、键、TTL、失效范围及故障行为。复杂机制仅在默认方案不足时引入;并发与传播细节按需读一致性与重建。
  4. 验证与交付:针对改变的行为验证正常、并发及失败路径,输出结论、风险和验证结果。简单任务只覆盖相关部分,不机械执行全量检查。

三、读取、写入与失效

3.1 读取与回填

读缓存 → 有效命中 → 返回
       → 未命中 → 查询数据库 → 回填缓存并设置 TTL → 返回
       → 缓存异常 → 按降级策略受控回源或快速失败
  • 区分未命中、缓存故障和数据损坏;格式不兼容或反序列化失败可视为无效缓存并回源,同时记录异常。
  • 数据库查询成功后,缓存写入或序列化失败通常不影响返回已取得的结果;数据库超时、异常不得缓存为“不存在”。
  • 回填与 TTL 应使用产品支持的原子操作,避免写入成功、设置过期失败留下永久键。
  • 热点回填需要请求合并或受控重建;同时检查旧请求晚回填和只读副本延迟,不能把“回源”自动等同于“读到最新值”。

3.2 写入与失效范围

提交数据库事务 → 成功 → 删除受影响缓存 → 后续读取重建
               → 失败 → 返回数据库错误,不执行成功后的失效流程
  • 在事务成功提交后失效,不能仅在执行更新 SQL 后、提交前删除。数据库提交与缓存删除不是一个原子事务。
  • 覆盖新增、更新、删除、批处理、后台任务及其他服务的写入;失效范围包含详情、列表、聚合、查询结果及空值缓存。以数据依赖关系确定范围,避免漏删或无差别全量清理。
  • 删除须幂等。失败时记录并按一致性要求做有界重试、补偿或告警;还要考虑提交后进程崩溃、根本未发起删除的窗口。
  • 删除失败不能回滚已提交的数据库事务。默认不因此将已成功的业务写入报告为失败;若接口契约要求额外确认,明确已提交状态和请求幂等性,避免客户端盲目重试。

四、一致性方案选择

优先采用满足业务要求的最简单方案,高并发本身不是引入双删、消息队列或独立服务的理由。

需要解决的问题 可选方案与边界
普通读取可容忍短暂旧值 提交后删除,结合 TTL 和按需补偿;仍存在删除失败和旧数据回填窗口
旧读请求在删除后回填 按风险评估延迟双删或版本校验;前者降低概率,后者需完整的版本与原子写入协议
提交后失效任务不能丢失 评估事务 Outbox 或变更数据捕获(CDC),复用已有设施;传播延迟仍然存在
多服务或多级缓存 明确失效所有者、传播范围和各层的新鲜度;删除共享缓存不等于清除各进程本地副本
写后立即读到新值或严格新鲜度 考虑返回已提交结果、相关读取绕过缓存并使用满足要求的权威读路径;异步失效不提供强一致保证

实现或深入评审双删、Outbox、CDC、版本控制、多级失效时,先读一致性与重建。

五、缓存键与隔离

5.1 命名与数据维度

沿用清晰的项目约定;新键推荐“命名空间:业务域:资源:标识”,使用小写英文描述、稳定业务 ID 和清晰缩写,例如:

order-service:order:detail:ORD10001
user-service:tenant:t10001:profile:u20001

Read the full file on GitHub · 158 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 13d ago First seen · 158 lines · 99 tokens per session scan A 4e28e4ae8ec2

Subscribe to this mod's changes

cache-engineering is a skill published in the GitHub repository chaunsin/agent-skills (2 stars, last pushed 11d ago), licensed Apache-2.0. It adds 99 tokens to every session and 3,057 once invoked, about $0.0004 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-11-17.

Related

cache-engineering compared with skills from other repositories

cache-engineering next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
cache-engineeringchaunsin/agent-skillsSkill211d agoApache-2.0A99Claude Code, Codex
azure-cache-redisMicrosoftDocs/Agent-SkillsSkill82422d agoCC-BY-4.0A115Claude Code
azure-managed-redisMicrosoftDocs/Agent-SkillsSkill82422d agoCC-BY-4.0A86Claude Code
laravel-asyncFoysal50x/skillsSkill121mo agoMITA86Claude Code
upstash-redis-kvintellectronica/agent-skillsSkill3057mo agoCC0-1.0A74Claude Code, Codex
offline-first-expertJosephSanjaya/skillsSkill51mo agoMITA57Claude Code, Codex
elasticache-redisAlexK020908/infra-designerSkill25mo agoMITA0Claude Code