You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 21, 2025. It is now read-only.
Donald Dong edited this page Apr 23, 2021
·
1 revision
With Rails low-level caching, race conditions between cache invalidation and cache writing would lead to cache inconsistency. For example:
Process A: Fetch from the cache, cache miss. Read user.display_name.
Process B: Update user.display_name, then invalidate the cache.
Process A: Write the previously read user.display_name (which is now stale) to the cache. All subsequent requests would use the stale data from the cache.
With RedisMemo
Since RedisMemo is version-addressable, the race condition would not happen:
Process A: Fetch from the cache, cache miss. Read user.display_name.
Process B: Update user.display_name, then bump the dependency version for that user.
Process A: Write the previously read user.display_name to the cache using the old user dependency version -- it is only referenceable using the old dependency version. All subsequent requests would use the new dependency version process B has just set, data associated with the old dependency version is no longer referenceable, thus the stale data has been discarded.