# API Caching Engineer

> Implements API caching with invalidation strategies: HTTP headers, Redis cache-aside with TTL, and event-driven invalidation. Use when working with http header caching, event invalidation or when the user mentions http header caching, event invalidation.

- Skill: `opknock/api-caching-engineer` (Agent Skill)
- Install (CLI): `npx get-skill add opknock/api-caching-engineer`
- Raw SKILL.md: https://api.skillmd.com/api/skills/opknock/api-caching-engineer/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-caching-engineer

---


Implements API caching with invalidation strategies: HTTP headers, Redis cache-aside with TTL, and event-driven invalidation.

## Agentic Workflow: Read -> Reason -> Act (api-caching-engineer)

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

### 1. Read — infrastructure context for `api-caching-engineer`
- Domain: Implements API caching with invalidation strategies: HTTP headers, Redis cache-aside with TTL, and event-driven invalidation.
- **http-header-caching**: Apply Cache-Control, ETag, and Vary for safe HTTP caching — `curl -s -D - http://localhost:3000/api/products | grep -i -E 'cache-control|etag`
- **event-invalidation**: Invalidate cache entries on domain events with pub/sub — `redis-cli PUBLISH product.updated '{"id":42}'`
- Check `knowledge` and `prerequisites: redis, node.js, python, varnish`

### 2. Reason — think for `api-caching-engineer`
- For `http-header-caching`: Apply Cache-Control, ETag, and Vary for safe HTTP caching — decide which checks to run
- For `event-invalidation`: Invalidate cache entries on domain events with pub/sub — decide which checks to run
- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs

### 3. Act — execute with `api-caching-engineer` 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-caching-engineer:113083cf`

# API Caching Engineer

Implements caching with disciplined invalidation so data stays fresh.

## When to Use
- Repeated reads hammer the database
- Stale data incidents from bad TTLs
- Adding caching to specific endpoints

## Real Commands

```bash
# Verify headers
curl -s -D - http://localhost:3000/api/products | grep -i -E 'cache-control|etag|vary'

# Conditional requests
curl -s -H 'If-None-Match: W/"etag1"' -o /dev/null -w '%{http_code}' http://localhost:3000/api/products

# Event-driven invalidation
redis-cli PUBLISH product.updated '{"id":42}'
redis-cli DEL api:products:42

# Namespace flush
redis-cli --scan --pattern 'api:products:*' | xargs -r redis-cli DEL
```

## Invalidation Rules
- Writes delete the affected keys
- Domain events drive scoped deletion
- Never wait for TTL for correctness

## Testing
Write a test that updates a resource and asserts the next read misses.

## Best Practices
- Invalidate by namespace patterns, not single keys
- Keep TTLs generous but never load-bearing

## Capabilities

### http-header-caching
Apply Cache-Control, ETag, and Vary for safe HTTP caching

**Parameters:**
- `url` (string): Endpoint URL
- `ttl` (string): Cache-Control max-age

**Commands:**
- `curl -s -D - http://localhost:3000/api/products | grep -i -E 'cache-control|etag|vary'`
- `curl -s -H 'If-None-Match: W/"etag1"' -o /dev/null -w '%{http_code}' http://localhost:3000/api/products`
- `curl -s -H 'If-Modified-Since: Mon, 10 Aug 2026 00:00:00 GMT' -o /dev/null -w '%{http_code}' http://localhost:3000/api/products`
- `curl -s -X POST http://localhost:3000/api/products -H 'Content-Type: application/json' -d '{}' -D - | grep -i cache-control`
- `curl -s -o /dev/null -w '%{http_code}' -H 'Cache-Control: no-cache' http://localhost:3000/api/products`

**Examples:**
- curl -s -D - http://localhost:3000/api/products | grep -i -E 'cache-control|etag|vary'
- curl -s -H 'If-None-Match: W/"etag1"' -o /dev/null -w '%{http_code}' http://localhost:3000/api/products
- curl -s -X POST http://localhost:3000/api/products -H 'Content-Type: application/json' -d '{}' -D - | grep -i cache-control

### event-invalidation
Invalidate cache entries on domain events with pub/sub

**Parameters:**
- `channel` (string): Redis pub/sub channel
- `keyPattern` (string): Keys to invalidate

**Commands:**
- `redis-cli PUBLISH product.updated '{"id":42}'`
- `redis-cli SUBSCRIBE product.updated`
- `redis-cli DEL api:products:42`
- `redis-cli --scan --pattern 'api:products:*' | xargs -r redis-cli DEL`
- `redis-cli SET api:products:42 '{}' EX 60 NX`

**Examples:**
- redis-cli PUBLISH product.updated '{"id":42}' && redis-cli DEL api:products:42
- redis-cli --scan --pattern 'api:products:*' | xargs -r redis-cli DEL
- redis-cli SUBSCRIBE product.updated

## References
- [Redis Pub/Sub](https://redis.io/docs/latest/develop/use/pubsub/)
- [HTTP Caching Semantics](https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching)

