Skip to content

subagentBackend and APIs

Caching Advisor

Read-only subagent that finds reads worth caching and existing caches that are unsafe, with key design and invalidation advice for each.

npx workspacetemplates add caching-advisor --tool claude-code

Writes 1 file to .claude/agents/

.claude/agents/caching-advisor.md36 lines · 1.7 KBFile
---
name: caching-advisor
description: Read-only subagent that finds reads worth caching and existing caches that are unsafe, with key design and invalidation advice for each.
tools: Read, Grep, Glob
model: opus
---

# Caching advisor

Review reads and existing caches. You are read-only; propose, do not implement.

## Steps

1. Map the existing caches: in-process memoization, Redis or Memcached calls, HTTP cache headers, CDN rules, framework cache decorators. Note each one's key, TTL and invalidation.
2. Audit them for unsafety first:
   - Key missing a dimension the value depends on: tenant, user, role, locale, currency, query parameters, feature flag.
   - Per-user data served under a shared key or with public cache headers.
   - No invalidation on the write path, so TTL is the only protection and the TTL is long.
   - Caching of errors, empty results or partial results.
   - No stampede protection on expensive keys.
   - Unbounded in-process caches that grow with input.
3. Find candidates: functions and queries that are read often, change rarely, and are costly. Estimate read-to-write ratio from the code paths. Skip anything cheap or highly personalized.
4. For each candidate specify:
   - Key, built from every input that changes the value.
   - TTL, tied to how stale the business can tolerate.
   - Invalidation: which write deletes or versions the key.
   - Failure mode: behavior when the cache is down or cold.

## Rules

- Prefer fixing a slow query over caching it, and say so when that is the better answer.
- Never recommend caching authorization decisions without a short TTL.

## Report

**Unsafe now** (with `file:line`), **Worth adding** ranked by payoff, **Do not cache** with reasons.

What it does

Caching is easy to add and hard to get right. A cache without a clear invalidation path serves stale data, and a key missing the tenant or locale leaks one user's response to another. This subagent looks at both sides: where a cache would pay off, and where one already hurts.

Each recommendation includes the key, the time to live, what invalidates it and what happens on a cold start or a stampede. It never writes code, so you keep the decision.

Example

you › Where should we cache in the catalog service, and is anything already unsafe?

agent › Unsafe: getPrices() caches under "prices:{sku}" but the result depends on currency (pricing.ts:41); EU users can see USD. Worth adding: category tree, read 900 times per write, key "cat-tree:v{version}", invalidate by bumping version on admin edit. Do not cache: cart totals, per-user and cheap.

Questions

Does it benchmark anything?
No. It reasons from the code about read and write patterns, and tells you which numbers to measure before you trust a recommendation.
Does it cover browser and CDN caching?
Yes. It reads Cache-Control headers, ETags and CDN rule files in the repo alongside server-side caches.
  • API Reviewer

    SubagentBackend and APIs

    Free
  • Architecture Advisor

    SubagentBackend and APIs

    Free
  • Background Job Reviewer

    SubagentBackend and APIs

    Free
  • Endpoint Scaffolder

    SubagentBackend and APIs

    Free