Repository navigation
feat(cache-manager)!: lock get_or_set() by default - #414
Merged
Merged
Conversation
CacheManager(lock=...) now defaults to True, including the manager AppCache creates, so concurrent misses of one key run factory once. The 0.3.9 FutureWarning is removed. CacheManager(lock=None) raises TypeError; get_or_set(lock=None) still inherits the manager's setting. APP_CACHE gains a Cost section with the backend round trips per hit, miss and waiting caller, and MIGRATING_0_4 covers the new default, the wait behaviour and the lock key. BREAKING CHANGE: get_or_set() uses stampede protection unless lock=False is passed to the call or to CacheManager(). A miss costs six backend round trips instead of two on Redis and Memcached, and waiting callers block until the first caller's factory returns. CacheManager(lock=None) raises TypeError. Closes #280
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #280.
Changes
CacheManager(lock=...)defaults toTrue, so the managerAppCachecreates locks too. Concurrent misses of one key runfactoryonce; the other callers wait for its result.FutureWarningfor an unsetlockis removed.CacheManager(lock=None)raisesTypeError.get_or_set(lock=None)still inherits the manager's setting.APP_CACHE.mdreplaces "The default changes in 0.4.0" with a Cost section. It lists backend round trips for a hit (1), an uncontended miss (2 → 6 on Redis/Memcached) and each waiting caller (2 per poll).MIGRATING_0_4.md#get-or-set-lockcovers the new default, theTypeError, waiting latency (lock_ttl/wait_timeout) and thelock:<prefix><key>key.examples/app_cache.pydrop the now-redundantlock=True.Tests
lock=True.cache_managerfixture and two single-backend tests no longer pinlock=False.Falsefails 6 tests, including the Redis and Memcached runs.lock=Nonefailstest_stampede_protection_validation.Gates from #280