- class GenerationSynchronizer(cache_key, normalize_cache_key=True)¶
Manages the synchronization of generation state across processes.
This is a utility class that makes it easy for consumers to synchronize a generation ID between processes and servers. This ID can be used to check whether a process has the latest version of some data, updating if the version it has is expired.
Callers should create a
GenerationSynchronizerwith a stable cache key, which will be used for communication between processes/servers. The initial generation number will be fetched, or created if one does not already exist.
When the caller has updated something in the state, it must call
mark_updated(). This will bump the synchronization generation number, which will invalidate other processes.
The synchronization cache key.
Return whether the current state has expired.
Trueif the state has expired.
Falseif this has the latest cached generation.
- Return type
Refresh the generation ID from cache.
This should be called after having updated to the latest state.
Clear the cached generation ID.
This will expire all existing caches and force all processes to re-fetch and store the cache state.
Mark the synchronized state as having been updated.
All other processes will find their state expired, and will need to re-update.