Skip to content

fix(backends): warn on every Memcached clear_path() call - #342

Merged
allen0099 merged 1 commit into
masterfrom
fix/memcached-clear-path-warning-320
Sep 28, 2026
Merged

allen0099 merged 1 commit into
masterfrom
fix/memcached-clear-path-warning-320

Conversation

@allen0099

Copy link
Copy Markdown
Owner

Problem

MemcachedBackend.clear_path(path) deletes only a key named exactly path. HTTP cache keys are method|||host|||path|||query, so it never removes a cached response. Only include_params=True warned; the default call returned 0 silently, so the "clear the path after a write" pattern kept serving stale data on Memcached (#320).

Change

  • clear_path() on Memcached emits a RuntimeWarning on every call, pointing to invalidate(request), which rebuilds the route's exact key and works on every backend. Behaviour is otherwise unchanged (the literal key is still deleted).
  • BACKENDS.md limitations, the clearing section of HTTP_CACHING.md and the Memcached notes in CACHE_FLOW.md say so, with zh-TW mirrors. examples/http_cache.py notes it next to its clear_path() call.
  • changelog.d/320.fixed.md.

Callers running with warnings as errors will now see the warning on the default call; that is the point of the change.

Tests

  • test_memcached_clear_path_always_warns[False|True] (stubbed client, checks the warning points at the caller).
  • test_memcached_invalidate_drops_what_clear_path_cannot: the report's scenario on a live Memcached. clear_path() warns and leaves the stale response; invalidate() removes it.
  • Existing clear_path tests now expect the warning.

Without the source change, 8 tests in tests/backends/test_memcached.py fail. Full suite, ruff, mypy strict and pre-commit pass.

Closes #320

Memcached cannot enumerate keys, so clear_path() only deletes a key named
exactly as the path and never matches an HTTP cache key
(method|||host|||path|||query). Only include_params=True warned, so the
default call returned 0 silently and a response stayed cached after a
write. Warn on every call and point to invalidate(request), which rebuilds
the route's exact key; document that in BACKENDS.md and HTTP_CACHING.md.

Closes #320
@allen0099 allen0099 added this to the 0.3.9 milestone Sep 28, 2026
@allen0099 allen0099 added bug Something isn't working backends Cache backends and their atomic primitives developer-experience Surprising behaviour, missing warnings or unclear errors for library users labels Sep 28, 2026
@allen0099
allen0099 merged commit de12fd3 into master Sep 28, 2026
12 checks passed
@allen0099
allen0099 deleted the fix/memcached-clear-path-warning-320 branch September 28, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backends Cache backends and their atomic primitives bug Something isn't working developer-experience Surprising behaviour, missing warnings or unclear errors for library users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memcached: clear_path() never matches an HTTP cache key and warns only with include_params

1 participant