fix(backends): warn on every Memcached clear_path() call - #342
Merged
Merged
Conversation
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
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.
Problem
MemcachedBackend.clear_path(path)deletes only a key named exactlypath. HTTP cache keys aremethod|||host|||path|||query, so it never removes a cached response. Onlyinclude_params=Truewarned; the default call returned0silently, so the "clear the path after a write" pattern kept serving stale data on Memcached (#320).Change
clear_path()on Memcached emits aRuntimeWarningon every call, pointing toinvalidate(request), which rebuilds the route's exact key and works on every backend. Behaviour is otherwise unchanged (the literal key is still deleted).examples/http_cache.pynotes it next to itsclear_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.clear_pathtests now expect the warning.Without the source change, 8 tests in
tests/backends/test_memcached.pyfail. Full suite, ruff, mypy strict and pre-commit pass.Closes #320