Skip to content
Back to skills

Caching Strategy

ASecurity

Multi-layer caching: HTTP, CDN, Redis, in-memory, browser. Invalidation, TTLs, stampede protection.

  • 3 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 14, 2026
databasesgoreactapidatabasebackend

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 5 files and shows the line behind each finding

Scanned November 14, 2026

npx -y skills add SebastianLuser/claude-code-arcane --skill caching-strategy --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Caching Strategy?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Caching Strategy
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/sebastianluser-caching-strategy/badge)](https://www.skillsdirectory.com/skills/sebastianluser-caching-strategy)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: caching-strategy
description: "Multi-layer caching: HTTP, CDN, Redis, in-memory, browser. Invalidation, TTLs, stampede protection."
category: "backend"
argument-hint: "[layer: http|cdn|redis|memory|browser]"
user-invocable: true
allowed-tools: Read, Glob, Grep, Write, Edit, Task
---
# caching-strategy — Multi-Layer Caching

**Rule 0:** measure before you cache. Caching without profiling hides problems.

## When to use / NOT use

| Use | Do NOT use |
|------|---------|
| Hot path with reads >> writes | Write-heavy with unpredictable reads |
| Expensive query with no possible indexes | Financial/regulatory info (staleness = legal damage) |
| Immutable or slow-changing response | Patch for a badly designed query (fix the query) |
| DB relief under load | Prematurely (indexes first) |

## Layers

```
Browser/RN → CDN → API Gateway → App in-memory (LRU) → Redis → Database
```

Each layer: a different TTL, a different invalidation. Closer to the user = more caching but harder to invalidate.

## What to cache where

| Data | Cache |
|------|-------|
| Static assets (JS, CSS, img) | CDN + browser (immutable + versioned URLs) |
| Public API responses | CDN + Redis |
| Per-user API responses | Redis + client |
| Session/token, rate limit counters | Redis |
| Translations / config | In-memory warm on boot |
| DB query result | Redis (cache-aside) |

## HTTP Caching Headers

> → Read references/http-headers.md for header values and ETag usage

## Patterns, Invalidation & Stampede Protection

> → Read references/patterns-and-invalidation.md for cache-aside/write-through/read-through patterns, invalidation strategies, and stampede protection

## TTL Defaults

> → Read references/ttl-defaults.md for recommended TTLs by data type

## Redis & Client-Side

> → Read references/redis-and-client.md for Redis cluster config, key naming, and React/RN client caching

## Anti-patterns

- Caching without measuring, infinite TTL without invalidation, caching PII without `no-store`
- Caching errors (404/500), cache fails → app goes down (the cache must be optional)
- `KEYS *` on prod Redis (use SCAN), cache without a namespace, per-user on a CDN without Vary
- No hit rate metrics

## Observability

- Metrics: `cache_hits/misses_total`, `cache_latency_seconds`, `cache_evictions_total`
- Hit rate target: hot >90%, warm >70%. Sustained hit rate <50% = the cache is not worth it
- Alerts: growing evictions, latency p99 >10ms, hit rate drops suddenly

## Checklist

- [ ] Profiling justifies the cache
- [ ] Correct layer chosen (browser/CDN/Redis/memory)
- [ ] TTL reasoned with the staleness vs. load trade-off
- [ ] Clear invalidation strategy
- [ ] Stampede protection if hot path
- [ ] Optional cache — the app works if Redis is down
- [ ] Correct HTTP headers (`private` for PII, `Vary`)
- [ ] Consistent key naming + namespace
- [ ] Metrics: hits/misses/latency/evictions
- [ ] We do not cache errors

Files in this skill

  • SKILL.md2.9 KB
  • references/http-headers.md342 B
  • references/patterns-and-invalidation.md1.1 KB
  • references/redis-and-client.md498 B
  • references/ttl-defaults.md321 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in databases →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.