Skip to content
Back to skills

Caching Strategies

ASecurity

Add caching (HTTP, CDN, in-process, Redis) with correct keys, TTLs, invalidation and stampede protection

  • 7 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 30, 2026
ai-agentsdebuggingapibackendperformance

Works with

  • api

Security analysis

A100/100

Scanned November 30, 2026

npx -y skills add ansh44233/forge --skill caching-strategies --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Caching Strategies?

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

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

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
---
description: Add caching (HTTP, CDN, in-process, Redis) with correct keys, TTLs, invalidation and stampede protection
profile: standard
tags: caching, performance, backend
---

# Caching strategies

Use when adding a cache or debugging stale or inconsistent data.

## Decide first
1. Measure: what is slow, and how often is the same answer requested? Cache only what is expensive and reused.
2. Choose the layer: HTTP caching (`Cache-Control`, `ETag`) and CDN for public responses, in-process for small hot data, Redis/Memcached for data shared across instances.
3. Decide the staleness the product can accept. That number is your TTL.

## Correctness
- Key everything that changes the answer: user or tenant id, locale, permissions, query parameters, API version. A missing key component leaks one user's data to another.
- Never cache responses that include `Set-Cookie` or personal data in a shared cache; use `Cache-Control: private` or `no-store`.
- Invalidate on write (delete the key after the transaction commits) or use versioned keys; TTL is the safety net, not the plan.
- Cache-aside: read the cache, on miss load from the source and set the key. Handle cache outages by falling back to the source.

## Stampedes and memory
- Protect hot keys from thundering herds with request coalescing (single-flight), locks, or probabilistic early refresh.
- Bound in-process caches (LRU with a max size). Set `maxmemory` and an eviction policy on Redis.
- Add jitter to TTLs so keys do not expire together.

## Verify
Tests for hit, miss, invalidation after write, and per-user isolation. Watch hit ratio and latency after release.

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 ai-agents →

Comments

Loading comments…

Newsletter

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