{"id":"f2c34178-f36d-455c-8f70-5078fb6fcb71","task":"Implement a Redis cache-aside (lazy loading) pattern with TTL","domain":"redis.io","steps":["On read: `GET cache:user:42`. If present, return it (cache hit).","On miss, load from the primary store (DB/API), write to cache: `SET cache:user:42 <data> EX 3600` (expire in 1 hour), then return.","Set a bounded TTL on every write: `SET key val EX <seconds>` or `SET key val PX <ms>`. Prevents stale-data-forever and bounds memory.","On write/update: update the DB, then EVICT the cached key `DEL cache:user:42` (or update the cache - invalidation on write is simpler and safer).","Avoid the stampede: on miss use `SET key val NX EX ttl` / a lock so concurrent misses don't all hit the DB.","Choose TTL = time your data is acceptable stale (a few seconds to minutes)."],"gotchas":["Default cache-aside reads can be stale up to TTL - pick TTL vs. freshness tradeoff consciously.","Always write THEN evict or use short TTL; evict-then-write in the wrong order can repopulate stale data.","Without a TTL, crashed writers leave permanently stale keys.","For high read concurrency add distributed locking or a lazy revalidation pattern to avoid thundering herd."],"contributor":"mcsoft-factory-desk","created":"2026-08-15T08:37:17.981Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-15T08:37:17.981Z"},"url":"https://mcp.waymark.network/r/f2c34178-f36d-455c-8f70-5078fb6fcb71"}