Skip to content

feat(cache-manager)!: lock get_or_set() by default - #414

Merged
allen0099 merged 1 commit into
masterfrom
feat/280-get-or-set-lock-default
Sep 30, 2026
Merged

allen0099 merged 1 commit into
masterfrom
feat/280-get-or-set-lock-default

Conversation

@allen0099

Copy link
Copy Markdown
Owner

Closes #280.

Changes

  • CacheManager(lock=...) defaults to True, so the manager AppCache creates locks too. Concurrent misses of one key run factory once; the other callers wait for its result.
  • The 0.3.9 FutureWarning for an unset lock is removed.
  • CacheManager(lock=None) raises TypeError. get_or_set(lock=None) still inherits the manager's setting.
  • Docs:
    • APP_CACHE.md replaces "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-lock covers the new default, the TypeError, waiting latency (lock_ttl / wait_timeout) and the lock:<prefix><key> key.
    • README, zh-TW index and examples/app_cache.py drop the now-redundant lock=True.
    • All doc changes are in both languages.

Tests

  • The default-path tests now assert that the lock is used.
  • The live stampede test across memory, Redis and Memcached now relies on the default instead of passing lock=True.
  • The shared cache_manager fixture and two single-backend tests no longer pin lock=False.
  • Mutation checks:
    • Reverting the default to False fails 6 tests, including the Redis and Memcached runs.
    • Accepting lock=None fails test_stampede_protection_validation.

Gates from #280

  • Opt-in shipped in 0.3.9.
  • Re-entrancy guard shipped.
  • Live tests across backends exist.
  • No open bugs against the feature.
  • Per-miss overhead is now documented.

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
@allen0099 allen0099 added this to the 0.4.0 milestone Sep 30, 2026
@allen0099 allen0099 added enhancement New feature or request cache-manager Application-level CacheManager breaking-change Changes public behaviour or API; needs a minor/major release labels Sep 30, 2026
@allen0099
allen0099 merged commit 891b340 into master Sep 30, 2026
16 checks passed
@allen0099
allen0099 deleted the feat/280-get-or-set-lock-default branch September 30, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change Changes public behaviour or API; needs a minor/major release cache-manager Application-level CacheManager enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0.4.0: enable get_or_set() stampede protection by default

1 participant