Skip to content

.tip

· one of the small things

Bump a version in the cache key instead of flushing

A deploy changes the shape of a cached value, and now every entry the old code wrote is wrong. Deleting them means scanning the whole keyspace for a pattern, and a flush dumps the entire working set on the database in one second. Put a version in the key and bump it along with the code.

const VERSION = 3; // raise when the value's shape changes
const key = `v${VERSION}:user:${id}:profile`;

The new code stops reading the old keys the moment it ships, and they expire on their own TTL. A rollback still finds its entries where it left them.

cachingoperations