caching-strategy

Installation
SKILL.md

Caching Strategy

Caching is the last step, not the first. If perf-audit hasn't been run, or the query is slow because of an N+1 or a missing index, fix that first; caching a bad query just hides it until the cache is cold.

Step 1: Is it worth caching?

Cache only if all of these hold:

  • It's read much more often than it changes.
  • It's expensive (measured: slow query, heavy aggregation, external API call, big render).
  • Slightly stale data is acceptable, or you can invalidate it reliably on every write.

Ask the dev (or the PRD) how stale is acceptable: "a few seconds", "until the next write", "an hour". That number drives the design.

Step 2: Pick the layer

Check CACHES in settings first; know the backend (Redis via django-redis or Django's built-in RedisCache, memcached, LocMemCache). LocMemCache is per-process: with multiple workers, invalidation won't reach the others, so don't rely on it for anything that's invalidated on write.

Installs
1
GitHub Stars
1
First Seen
8 days ago