Repository navigation
feat(backends)!: make delete() return whether a key was removed - #427
Merged
Merged
Conversation
BaseCacheBackend.delete() now returns bool on memory, Redis and Memcached. The base delete_many() fallback counts only keys that existed, and the get_and_delete() / delete_if_equals() fallbacks no longer let a caller win after its delete found the key gone.
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 #71.
BaseCacheBackend.delete()returns whether a key was removed, instead ofNone.Changes
async def delete(self, key: str) -> bool.Truewhen the key held an entry that had not expired. An expired entry is still dropped but counts as absent, matching_evict(delete_many,clear_pattern,clear_path) and RedisDEL.DELcount, as a bool.delete(noreply=False)'s answer.clear_path()now reusesdelete()instead of duplicating it.delete_many()counts only the keys that existed, not the ones attempted.get_and_delete()anddelete_if_equals()use the result, so a caller whose delete found the key already gone no longer also wins. They are still non-atomic, as documented.changelog.d/71.changed.md. The migration sectionMIGRATING_0_4.md#backend-delete(EN and zh-TW) already describes this change and is unchanged.Tests
Trueon the first delete andFalseon the second. Memory also checks that deleting an expired entry returnsFalse.noreply=Falseand the namespaced key, so it runs without a server.test_base.py: thedelete_manyfallback count, and the fallbacks losing a race between their get and delete.Trueunconditionally, restoring the old fallbacks, or droppingnoreply=Falseeach fails the tests that guard it.An independent review agent reviewed the change before this PR. It found nothing blocking; its optional suggestions (stubbed Memcached test, fallbacks using the result,
clear_pathreuse) are included.