Delete
user:42 so the next read reloads it from the databaseDelete the key, so the next read reloads it from the database. Deleting is idempotent: doing it twice gives the same result as doing it once. It also avoids a race between two writers. Imagine two requests update the user at the same time, and their cache writes arrive in the wrong order. The older value can end up in the cache.
"Overwrite user:42 with the new value" looks fresher, but it is exactly where that race happens. "Leave it and let the TTL expire" serves stale (old) data for the whole TTL.
Read more