Skip to content
Skills Library
Programming · Building & coding

caching

/caching

Use when adding or debugging a cache. Covers cache placement, invalidation strategies, stampede protection, TTL selection, and the consistency you are trading away. Trigger on "add redis caching", "users are seeing stale data", "cache stampede after expiry", "should we cache this". Do not use for browser caching headers and page load — see the web-performance skill; for a query that is slow at the source, see the database-performance skill.

Licence
MIT
Last repository change
24.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 24.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Use when adding or debugging a cache. Covers cache placement, invalidation strategies, stampede protection, TTL selection, and the consistency you are trading away. Trigger on "add redis caching", "users are seeing stale data", "cache stampede after expiry", "should we cache this". Do not use for browser caching headers and page load — see the web-performance skill; for a query that is slow at the source, see the database-performance skill.

Triggers from the description

add redis cachingusers are seeing stale datacache stampede after expiryshould we cache this
Original author description

Use when adding or debugging a cache. Covers cache placement, invalidation strategies, stampede protection, TTL selection, and the consistency you are trading away. Trigger on "add redis caching", "users are seeing stale data", "cache stampede after expiry", "should we cache this". Do not use for browser caching headers and page load — see the web-performance skill; for a query that is slow at the source, see the database-performance skill.

How it works

  1. Purpose
  2. When to Use
  3. Capabilities
  4. Inputs
  5. Outputs
  6. Workflow
  7. Best Practices
  8. Examples
  9. Notes
Original SKILL.md headings · 87 lines, 674 words
SKILL.md preview
---
name: caching
description: Use when adding or debugging a cache. Covers cache placement, invalidation strategies, stampede protection, TTL selection, and the consistency you are trading away. Trigger on "add redis caching", "users are seeing stale data", "cache stampede after expiry", "should we cache this". Do not use for browser caching headers and page load — see the web-performance skill; for a query that is slow at the source, see the database-performance skill.
metadata:
  category: backend
  version: 1.0.0
  tags: [caching, redis, invalidation, performance, stampede]
---

# Caching

## Purpose

Add a cache with a clear invalidation story, or find out why the existing one is serving stale data. A cache is a second source of truth; introducing one is a consistency decision, not just a performance one.

## When to Use

- A read path is slow and the data is read far more often than it is written.
- An upstream dependency is expensive, rate-limited, or unreliable.
- Debugging stale reads, cache stampedes, or unexplained memory growth.

## Capabilities

- Cache placement: client, CDN, application, database.
- Strategies: cache-aside, read-through, write-through, write-behind.
- Invalidation: TTL, explicit, event-driven, versioned keys.
- Stampede protection: locking, early recomputation, request coalescing.
- Negative caching and hot-key mitigation.

## Inputs

- The read/write ratio and the cost of the uncached path.
- How stale the data is allowed to be — in seconds, agreed with the product owner.
- Cardinality of the key space and expected memory footprint.

## Outputs

- A key schema, a TTL, and an invalidation trigger for each cached entity.
- Stampede protection on any key expensive enough to matter.
- A hit-rate metric, because a cache you do not measure is a cache you do not understand.

## Workflow

1. **Prove the need** — Measure the uncached path first. A cache in front of a missing index is a permanent workaround for a five-minute fix.
2. **Decide the staleness budget** — Ask what breaks if a user sees data five seconds old. The answer determines the TTL and whether you need explicit invalidation.
3. **Design the key** — Include everything that varies the result: tenant, locale, permission scope. A key that omits a dimension leaks data between users.
4. **Choose invalidation** — TTL alone for tolerant data. TTL plus explicit deletion on write for data that must be fresh. Versioned keys when deletion is unreliable.
5. **Protect against stampedes** — When a hot key expires, every concurrent request misses simultaneously and hits the origin at once. Use a lock or single-flight.
6. **Measure** — Hit rate, latency at each layer, and eviction rate. Falling hit rate with rising memory means the key space is too large.

## Best Practices

- Cache the expensive computation, not the whole response. Response-level caching multiplies the key space by every variant.
- A cache key missing the tenant or the user's permission scope is a data-leak vulnerability, and it will be found by a customer.
- Never cache with an unlimited TTL and rely on invalidation alone. Invalidation fails; the TTL is the safety net.
- Set memory limits and an eviction policy explicitly (`allkeys-lru`). A Redis instance with no `maxmemory` will be killed by the OOM killer.
- Do not cache errors indefinitely, but do cache "not found" briefly — otherwise a bad ID becomes an origin DoS.
- Warm caches before cutting traffic over. A cold cache under full load is an outage.

## Examples

**Single-flight cache-aside, preventing a stampede:**

```python
async def get_pricing(tenant_id: str, sku: str) -> Pricing:
    key = f"pricing:v3:{tenant_id}:{sku}"

    if (cached := await redis.get(key)) is not None:
        return Pricing.model_validate_json(cached)

    # Only one caller per key computes; the rest wait for the result.
    lock_key = f"{key}:lock"
    if await redis.set(lock_key, "1", nx=True, ex=10):
        try:
            pricing = await compute_pricing(tenant_id, sku)      # expensive
            await redis.set(key, pricing.model_dump_json(), ex=300)
            return pricing
        finally:
            await redis.delete(lock_key)

    # Lost the race: wait briefly for the winner, then fall back to computing.
    for _ in range(20):
        await asyncio.sleep(0.05)
        if (cached := await redis.get(key)) is not None:
            return Pricing.model_validate_json(cached)

    return await compute_pricing(tenant_id, sku)
```

## Notes

- The `v3` in the key is a schema version. When the cached shape changes, bump it — this invalidates the whole namespace atomically without a scan-and-delete.
- Adding jitter to TTLs (`ex=300 + random.randint(0, 60)`) prevents a cohort of keys written together from expiring together.
- A 95% hit rate sounds excellent, but if the 5% of misses are all on the single hottest key, the origin still sees the full load. Look at misses per key, not just the aggregate.

Versions

RepositoryScoreLicence
This page · nimadorostkar/Claude-Skills-collection100MIT
zebbern/claude-code-guide100MIT
nahid-sparktales/agent-dispatcher100MIT
codewithmukesh/dotnet-claude-kit100MIT
MARUCIE/openclaw-foundry100MIT
Tyler-R-Kendrick/agent-skills100MIT
kid-sid/codex-spellbook100MIT
proyecto26/system-design-skills90MIT

Database snapshot: 13.11.2026 · package version 6f2ceb67fb0e (SHA-256 digest of the entire package)

Downloads in the last 30 days: 1 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100caching-strategies
    Design multi-tier caching architectures for web applications — cache-aside vs write-through vs write-behind, TTL design, cache invalidation, Redis patterns, CDN configuration, browser caching, and stampede prevention. Use when choosing a caching pattern, designing cache…
  • 100cache-strategy
    Design and implement caching layers for APIs and web applications using Redis or Memcached. Use when you need to reduce database load, improve response times, or handle traffic spikes. Covers cache-aside, write-through, and write-behind patterns, TTL strategies, cache…
  • 100caching-strategies
    Designs caches that stay correct, covering where to cache (browser, CDN, application, distributed), cache-aside vs write-through, key design, TTLs, invalidation, stampede protection and HTTP Cache-Control headers. Use when adding Redis, Memcached, a CDN or HTTP caching, when…
  • 100caching-strategy
    Designs multi-layer caching - CDN, application, and database - choosing the pattern, TTL, and invalidation plan per data type, and produces a cache-decision table plus stampede protection. Use when someone asks "should I cache this", "Redis or CDN for this endpoint", "how do I…
  • 90role-backend:caching-strategies
    Implements caching solutions using Redis patterns (cache-aside, write-through, write-behind), Memcached, cache invalidation strategies, TTL design, cache stampede prevention, CDN configuration, and distributed caching. Use when optimizing read performance, reducing database…
  • 90backend-caching
    Use this skill when the user says 'cache', 'Redis', 'Memcached', 'CDN', 'cache-aside', 'read-through', 'write-through', 'write-behind', 'cache invalidation', 'TTL', 'cache stampede', 'thundering herd', 'cache warming', 'LRU', 'LFU', 'cache hit ratio', 'cache strategy', or when…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.