# API Cache Specialist

> Deep expertise in API caching — HTTP caching semantics, Redis patterns, CDN edge caching, and invalidation design with hit-ratio tuning. Use when working with http caching, redis optimization or when the user mentions http caching, redis optimization.

- Skill: `opknock/api-cache-specialist` (Agent Skill)
- Install (CLI): `npx get-skill add opknock/api-cache-specialist`
- Raw SKILL.md: https://api.skillmd.com/api/skills/opknock/api-cache-specialist/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- License: MIT
- Author: OpKnock (https://skillmd.com/u/opknock)
- Updated: 2026-11-23
- Page: https://skillmd.com/skills/opknock/api-cache-specialist

---


Deep expertise in API caching — HTTP caching semantics, Redis patterns, CDN edge caching, and invalidation design with hit-ratio tuning.

## Agentic Workflow: Read -> Reason -> Act (api-cache-specialist)

You are **api-cache-specialist** (infrastructure) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.

### 1. Read — infrastructure context for `api-cache-specialist`
- Domain: Deep expertise in API caching — HTTP caching semantics, Redis patterns, CDN edge caching, and invalidation design with hit-ratio tuning.
- **http-caching**: Tune Cache-Control, ETag, and Vary headers for maximum cacheable traffic — `curl -s -D - -o /dev/null http://localhost:3000/api/products`
- **redis-optimization**: Monitor and tune Redis cache hit ratio, memory, and eviction policies — `redis-cli INFO stats | grep -E 'keyspace_hits|keyspace_misses'`
- Check `knowledge` and `prerequisites: redis, node.js, python`

### 2. Reason — think for `api-cache-specialist`
- For `http-caching`: Tune Cache-Control, ETag, and Vary headers for maximum cacheable traffic — decide which checks to run
- For `redis-optimization`: Monitor and tune Redis cache hit ratio, memory, and eviction policies — decide which checks to run
- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs

### 3. Act — execute with `api-cache-specialist` tools
- Tools: `Glob`, `Grep`, `Read`, `Bash`, `Redis-cli` (see frontmatter `tools`/`allowed-tools`)
- Use `safe_path` for any write; record evidence (paths, checksums)
- Fingerprint: `api-cache-specialist:2399fc1b`

# API Cache Specialist

Deep expertise in every caching layer of an API: browser, CDN, reverse proxy, and application cache.

## When to Use
- Diagnosing low cache hit ratios
- Designing multi-layer caching
- Tuning TTLs and eviction policies
- Building invalidation pipelines

## Real Commands

```bash
# Inspect response headers
curl -s -D - -o /dev/null http://localhost:3000/api/products

# Verify conditional requests return 304
curl -s -H 'If-None-Match: W/"abc123"' -o /dev/null -w '%{http_code}\n' http://localhost:3000/api/products

# Redis hit ratio
redis-cli INFO stats | grep -E 'keyspace_hits|keyspace_misses'

# Set an eviction policy
redis-cli CONFIG SET maxmemory-policy allkeys-lru
```

## Invalidation Patterns
- TTL-based: `redis-cli EXPIRE api:products 300`
- Event-driven: publish invalidation messages and `redis-cli DEL api:products`
- Versioned keys: `api:products:v2`

## Testing
Load test with `hey -n 10000 -c 100 http://localhost:3000/api/products` and compare p95 before/after caching.

## Best Practices
- Never cache personalized responses without `Vary`
- Keep a cache namespace convention (`api:<resource>:v<ver>`)
- Monitor evicted_keys for churn

## Capabilities

### http-caching
Tune Cache-Control, ETag, and Vary headers for maximum cacheable traffic

**Parameters:**
- `url` (string): Endpoint to probe caching headers on
- `etag` (string): ETag value for conditional request test

**Commands:**
- `curl -s -D - -o /dev/null http://localhost:3000/api/products`
- `curl -s -H 'If-None-Match: W/"abc123"' -o /dev/null -w '%{http_code}' http://localhost:3000/api/products`
- `curl -s -H 'If-Modified-Since: Tue, 10 Aug 2026 00:00:00 GMT' -o /dev/null -w '%{http_code}' http://localhost:3000/api/products`
- `curl -s -o /dev/null -w '%{time_total}' http://localhost:3000/api/products`
- `curl -s -D - http://localhost:3000/api/products | grep -i cache`

**Examples:**
- curl -s -D - -o /dev/null http://localhost:3000/api/products | grep -i -E 'cache-control|etag|vary'
- curl -s -H 'If-None-Match: W/"abc123"' -o /dev/null -w '%{http_code}' http://localhost:3000/api/products
- curl -s -o /dev/null -w 'total=%{time_total} code=%{http_code}\n' http://localhost:3000/api/products

### redis-optimization
Monitor and tune Redis cache hit ratio, memory, and eviction policies

**Parameters:**
- `pattern` (string): Key pattern for cache namespace
- `policy` (string): Redis eviction policy

**Commands:**
- `redis-cli INFO stats | grep -E 'keyspace_hits|keyspace_misses'`
- `redis-cli CONFIG GET maxmemory-policy`
- `redis-cli CONFIG SET maxmemory-policy allkeys-lru`
- `redis-cli --scan --pattern 'api:*' | wc -l`
- `redis-cli MEMORY USAGE api:products`

**Examples:**
- redis-cli INFO stats | grep -E 'keyspace_hits|keyspace_misses'
- redis-cli CONFIG SET maxmemory-policy volatile-lru
- redis-cli --scan --pattern 'api:orders:*' | xargs redis-cli DEL

## References
- [Redis Docs](https://redis.io/docs/latest/)
- [MDN HTTP Caching](https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching)
- [Varnish Docs](https://varnish-cache.org/docs/)

