agent-instructions
Use when writing project instructions for a coding agent (CLAUDE.md, AGENTS.md, or equivalent). Covers what belongs in them, what does not, structure, and…
Use when adding or debugging a cache. Covers cache placement, invalidation strategies, stampede protection, TTL selection, and the consistency you are trading away.
$ npx -y skills add nimadorostkar/Claude-Skills-collection --skill caching --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/cachingContext preview
The summary Claude sees to decide when to auto-load this skill.
Use when adding or debugging a cache. Covers cache placement, invalidation strategies, stampede protection, TTL selection, and the consistency you are trading away.
name: caching description: Use when adding or debugging a cache. Covers cache placement, invalidation strategies, stampede protection, TTL selection, and the consistency you are trading away. metadata: category: backend version: 1.0.0 tags: [caching, redis, invalidation, performance, stampede]
Add a cache with a clear invalidation story, or find out why the existing one is serving stale data. A cache is a second source of truth; introducing one is a consistency decision, not just a performance one.
1. **Prove the need** — Measure the uncached path first. A cache in front of a missing index is a permanent workaround for a five-minute fix. 2. **Decide the staleness budget** — Ask what breaks if a user sees data five seconds old. The answer determines the TTL and whether you need explicit invalidation. 3. **Design the key** — Include everything that varies the result: tenant, locale, permission scope. A key that omits a dimension leaks data between users. 4. **Choose invalidation** — TTL alone for tolerant data. TTL plus explicit deletion on write for data that must be fresh. Versioned keys when deletion is unreliable. 5. **Protect against stampedes** — When a hot key expires, every concurrent request misses simultaneously and hits the origin at once. Use a lock or single-flight. 6. **Measure** — Hit rate, latency at each layer, and eviction rate. Falling hit rate with rising memory means the key space is too large.
**Single-flight cache-aside, preventing a stampede:**
async def get_pricing(tenant_id: str, sku: str) -> Pricing:
key = f"pricing:v3:{tenant_id}:{sku}"
if (cached := await redis.get(key)) is not None:
return Pricing.model_validate_json(cached)
# Only one caller per key computes; the rest wait for the result.
lock_key = f"{key}:lock"
if await redis.set(lock_key, "1", nx=True, ex=10):
try:
pricing = await compute_pricing(tenant_id, sku) # expensive
await redis.set(key, pricing.model_dump_json(), ex=300)
return pricing
finally:
await redis.delete(lock_key)
# Lost the race: wait briefly for the winner, then fall back to computing.
for _ in range(20):
await asyncio.sleep(0.05)
if (cached := await redis.get(key)) is not None:
return Pricing.model_validate_json(cached)
return await compute_pricing(tenant_id, sku)A curated library of 137 production-grade skills for Claude and other AI coding agents. Every skill follows one structure, speaks with one voice, and earns its place by changing what the agent does.
Repo: nimadorostkar/Claude-Skills-collection
Use when writing project instructions for a coding agent (CLAUDE.md, AGENTS.md, or equivalent). Covers what belongs in them, what does not, structure, and…
Use when an agent needs state that survives a session or a context compaction. Covers what to persist, file-based memory, structuring notes for retrieval, and…
Use when automating agent behavior with lifecycle hooks. Covers hook events, deterministic enforcement of rules the model should not be trusted to remember,…
Use when packaging skills, commands, hooks, and MCP servers into a distributable plugin. Covers manifest structure, bundling, versioning, testing, and…
Use when writing a new skill for an AI agent. Covers scoping, description writing for reliable triggering, progressive disclosure, and the difference between a…
Use when reviewing or improving an existing agent skill. Covers triggering accuracy, content quality, redundancy with the base model, and measuring whether the…