Bump a version in the cache key instead of flushing
A deploy changes the shape of a cached value, so every entry the old code wrote is now wrong. Deleting them means scanning the whole keyspace for a pattern, and a flush hands the database the entire working set in one second. Put a version in the key and raise it with the code.
const VERSION = 3; // raise when the value's shape changes
const key = `v${VERSION}:user:${id}:profile`;The old keys stop being read the moment the new code ships and they age out on their own TTL. A rollback still finds its own entries where it left them.
cachingoperations