RTS questionnaire · Q05 · Caching proof

Have you worked with caching technologies such as Redis or Memcached?

A runnable review of the cache strategies behind the answer: the operations I use in production, the code that implements them, and the criteria the answer is held to.

Status: reviewed Live cache workflow Redis · Memcached · .NET Jump to live proof ↓

5. Cache strategies: Redis and Memcached

Answer as submitted

“Yes — Redis (cache-aside, TTL, pub/sub, cluster), plus Memcached and CDN caching.”
Technical decision: expand. The submitted line is accurate but compressed — the questionnaire caps each answer at one short line, so it names the technologies without the discipline behind them. This page is the separate, detailed version: it shows the exact operations, the implementation in code, and the rules that keep a cache from turning into a source of stale data.

Expanded answer

Yes. Redis is my primary distributed cache and I apply it with cache-aside reads, write-through updates and an explicit invalidation contract built on TTLs, jittered expirations and pub/sub invalidation. Memcached I use for the same key/value cache-aside model where a slim, non-persistent store is enough, and I add in-process IMemoryCache memoisation for the hot in-node layer plus HTTP/CDN caching at the edge.

StrategyTypical operationWhat it is for
Cache-aside (read)GET → on miss SETEXServes repeated reads without touching the database.
Write-throughSET … EX <ttl>Keeps the entry fresh after the database write succeeds.
Jittered expiryTTL + random offsetStops a whole keyspace from expiring in the same second.
Pub/sub invalidationPUBLISH / SUBSCRIBEEvery node drops its own copy, so no stale replica survives.
Single-flight lockSET … NX PXTurns a stampede of misses into one database query.
In-process memoisationIMemoryCacheRemoves even the network hop for the hottest values.
Edge / HTTP cachingCache-Control, ETagAnswers static and cacheable API responses before the origin.

Live cache workflow proof

The running component below changes its command/result view through real event binding. Select an operation to see the exact Redis command, what the application does around it, and the observable result the caller receives.

LIVE PREVIEW
RUNNING
CACHE WORKFLOWRUNNING

Choose a cache operation

Select an operation to inspect the exact Redis command and its observable result.

$ GET user:42:profile

Cache-aside read: the value is in Redis, so the database is never touched and the request stays in the sub-millisecond range.

HIT  ·  0.4 ms  ·  TTL 267 s left
{"id":42,"name":"M. Cortes","plan":"senior"}

How caching fits this answer

Why an invalidation contract comes first. A cache is only as good as its worst stale read. Before adding one I define how entries expire and how they are invalidated — TTL plus jitter for normal expiry, an event for explicit invalidation, and a single-flight lock for the moment of a miss — and then I measure hit ratio and p95 latency to confirm the cache actually earns its complexity.
Boundary for Q05: this page covers caching technologies and the strategy around them. Cluster topology sizing, provider-specific failover configuration and cost modelling for managed Redis services are separate topics.

Source files

Select a file to inspect the proof with syntax highlighting and line numbers. The first file is the code running the component above; the other two are the production shapes of the same strategy.

Acceptance criteria