Cache invalidation

Cache invalidation deletes a cached key whenever a write path changes the underlying data represented by that key. The deletion should happen after the database transaction commits, rather than updating the cached value in place; TTL expiration provides a safety net for missed invalidations.

Minimal example

go
if err := tx.Commit(); err != nil {
	return err
}
return rdb.Del(ctx, key).Err()

Learn this concept

Lesson 6.1 · Cache-aside with jitter and singleflight

Used in exercises

Exercise 6.2 · Menu cache and stock updater
Prerequisite conceptsTransactionRedis TTL