When someone new takes on anything around application caching, we hand them approximately this list. It fits within one page.
The lessons
-
Refreshing the busiest keys a little ahead of expiry, by one process, ensures readers never pile onto the rebuild.
-
An overall hit rate near nine in ten can mask a group of keys that almost never hits, so we break the number down by key prefix.
-
Each cached value should have a clear answer to a single question: when does it go stale? Without that, the cache eventually hands out wrong data.
To show what this looks like, below is the Redis setup we use, in a trimmed form:
# cache only, nothing we cannot rebuild redis-cli CONFIG SET maxmemory 1gb redis-cli CONFIG SET maxmemory-policy allkeys-lru redis-cli INFO stats | grep keyspace redis-cli --scan --pattern 'menu:*' | head -n 20 redis-cli TTL menu:32995
The current state of our cache setup script lives in our codebase, with a short reason for every line in its comments.