Skip to content
Skills Library
Programming · Building & coding

cache-invalidation

/cache-invalidation

Keep cached data correct as the source changes using write-through, event-driven eviction, and versioned keys. Use when a cache exists and stale reads are a risk, or when users report seeing old data after a write.

Repository
AI-SKILLS ↗
Licence
MIT
Last repository change
05.09.2026

Assessment and security

90/ 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.
Content25 / 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 05.09.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

Keep cached data correct as the source changes using write-through, event-driven eviction, and versioned keys. Use when a cache exists and stale reads are a risk, or when users report seeing old data after a write.

Original author description

Keep cached data correct as the source changes using write-through, event-driven eviction, and versioned keys. Use when a cache exists and stale reads are a risk, or when users report seeing old data after a write.

How it works

  1. Method
  2. Litmus tests
  3. Boundaries
Original SKILL.md headings · 48 lines, 405 words
SKILL.md preview
---
name: cache-invalidation
description: Keep cached data correct as the source changes using write-through, event-driven eviction, and versioned keys. Use when a cache exists and stale reads are a risk, or when users report seeing old data after a write.
---

# Cache invalidation

The hard part of caching is not filling the cache, it is knowing the moment a
cached value became a lie. A stale read is a correctness bug wearing good
latency. Every cache needs a written answer to one question: when the source
changes, how does the copy learn?

## Method

1. **Enumerate every write path to the source of truth.** The API handler, the
   admin tool, the batch job, the replication stream, the manual database
   fix. Any path that mutates data and does not touch the cache is a stale-read
   generator. List them before choosing a mechanism.
2. **Prefer write-through or write-behind for data you own.** Update the cache
   in the same transaction or commit hook that updates the store, so the two
   move together. Write-through updates synchronously; write-behind queues the
   update. Either beats hoping a TTL expires before someone reads.
3. **Use events for cross-service invalidation.** When another service owns the
   write, subscribe to its change stream (Kafka, a Postgres logical
   replication feed, an outbox table) and evict on the event. Do not poll, and
   do not assume a short TTL papers over another team's write.
4. **Version keys instead of hunting them down.** For values derived from a
   schema or ruleset, embed a version in the key (`product:42:v7`). Bump the
   version and every consumer misses to fresh data at once, with no scan and
   no delete storm. Old keys age out on their own TTL.
5. **Invalidate the exact set, and its dependents.** Editing a product must
   drop `product:42` and any aggregate that includes it: the category listing,
   the search facet, the homepage block. Map these dependencies explicitly;
   the bug is always the derived key you forgot.
6. **Make eviction idempotent and failure-tolerant.** A delete that runs twice
   must be harmless, and a missed event must be recoverable by a bounded TTL as
   backstop. Never rely on the invalidation firing exactly once.

## Litmus tests

- Name a write path where the cache is not updated: if one exists, it leaks.
- After an edit, does every derived and aggregate key reflect it, not just the
  primary key?
- If an invalidation event is dropped, does a TTL still bound the staleness?

## Boundaries

This assumes the cache layout and TTLs are already chosen; that design belongs
to caching-strategy. Refresh scheduling for precomputed aggregates is handled
in materialized-views. Distributed multi-region coherence adds consensus
concerns beyond a single cache tier.

Versions

The database has no other skills named cache-invalidation.

Database snapshot: 13.11.2026 · package version 1bdfe9e97145 (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

  • 100cache-and-vary-invalidation-on-write
    Check whether a write invalidates the cached reads it should, because a stale read after a mutation is a correctness defect that only appears when you look. Use when responses can be cached and writes update the same data the cache serves
  • 90cache-evict
    Design a cache invalidation and eviction strategy — event-driven invalidation and thundering herd prevention. Use when asked to "design cache invalidation", "fix stale cache data", or "prevent a thundering herd".
  • 100redis-caching-strategy-and-invalidation-patterns
    Covers application-facing caching design on top of Redis: cache-aside vs. write-through vs. write-behind, TTL strategy (fixed, sliding, jittered), cache invalidation patterns (explicit delete, versioned keys, pub/sub fan-out) and their specific failure modes (stale reads,…
  • 100redis-cache-tests
    Use when Redis is the app's cache and its behavior needs tests, or when choosing a cache invalidation strategy: TTLs, cache-aside write and invalidate, eviction under memory pressure, pub/sub invalidation across nodes and tenant key namespaces, plus stampede and stale-while-revalidate patterns.
  • 100nextjs-caching
    Configure Next.js cache layers, invalidation, and cache-component APIs. Use when choosing `fetch` caching, `use cache`, tags, or stale-data debugging in Next.js.
  • 95backend-caching-strategies
    Use this skill when the user says 'cache-aside', 'write-through', 'write-behind', 'read-through', 'cache invalidation', 'redis cache pattern', 'cache stampede', 'thundering herd', 'TTL jitter', 'stale cache'. Picks and implements a Redis-backed caching pattern (cache-aside,…

Feedback and reports

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