feat: add cache_contains() for read-only key lookup#746
feat: add cache_contains() for read-only key lookup#746rodrigobnogueira merged 3 commits intoaio-libs:masterfrom
Conversation
|
Hi @rahulkaushal04 . Could you please add some documentation to the README.rst file? Probably something similar to the |
|
Hi @rodrigobnogueira, I have addressed all the review feedback:
Could you please take another look? Thanks! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #746 +/- ##
==========================================
+ Coverage 97.59% 97.78% +0.18%
==========================================
Files 15 16 +1
Lines 1081 1172 +91
Branches 60 61 +1
==========================================
+ Hits 1055 1146 +91
Misses 23 23
Partials 3 3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Merging this PR will not alter performance
Comparing Footnotes
|
|
Thanks @rahulkaushal04 👏 |
Add
cache_contains()method for checking if arguments are cachedWhat do these changes do?
This adds a
cache_contains(*args, **kwargs) -> boolmethod toalru_cache. It lets you check whether a specific set of arguments is currently in the cache. It returnsTrueif the key exists andFalseotherwise. It does not count as a hit or miss, does not trigger execution, and does not change LRU ordering.Are there changes in behavior for the user?
This is a purely additive change. No existing behavior is modified. Users who do not use
cache_containsare completely unaffected.For users who need this, it replaces two clunky workarounds that both have side effects:
Before:
cache_info()gives a total count, not per-key infoBefore:
cache_invalidate()removes the entry as a side effectAfter: clean read-only lookup
Works on instance methods too:
Related issue number
None. This is a new feature proposal with implementation included.
Checklist