Add argument-specific cache clearing#390
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #390 +/- ##
=======================================
Coverage 99.95% 99.95%
=======================================
Files 16 16
Lines 2109 2179 +70
Branches 251 255 +4
=======================================
+ Hits 2108 2178 +70
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds argument-specific cache invalidation to Cachier’s cache-management API, enabling callers to clear a single cached entry by providing the same call signature used to compute it (sync and async), across all supported backends.
Changes:
- Extend
clear_cache()/aclear_cache()to accept*args, **kwargsand clear only the matching cache entry when provided. - Introduce a core-level primitive
clear_cache_entry(key)with an async-compatibleaclear_cache_entry(key)default. - Add backend implementations and tests (smoke, async, and per-backend) plus README documentation.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_smoke.py | Adds smoke coverage for argument-specific cache clearing (function + method). |
| tests/test_base_core.py | Extends base-core test double and verifies aclear_cache_entry fallback. |
| tests/test_async_core.py | Adds async wrapper coverage for targeted cache clearing via aclear_cache. |
| tests/sql_tests/test_sql_core.py | Adds SQL backend test for clearing a single cache entry by args. |
| tests/s3_tests/test_s3_core.py | Adds S3 backend test for clearing a single cache entry by args. |
| tests/redis_tests/test_redis_core.py | Adds Redis backend test for clearing a single cache entry by args. |
| tests/mongo_tests/test_mongo_core.py | Adds Mongo backend test for clearing a single cache entry by args. |
| src/cachier/cores/sql.py | Implements SQL clear_cache_entry / aclear_cache_entry deletion by key. |
| src/cachier/cores/s3.py | Implements S3 clear_cache_entry deletion by object key. |
| src/cachier/cores/redis.py | Implements Redis clear_cache_entry / aclear_cache_entry deletion by key. |
| src/cachier/cores/pickle.py | Implements pickle clear_cache_entry, including separate-files mode deletion. |
| src/cachier/cores/mongo.py | Implements Mongo clear_cache_entry / aclear_cache_entry deletion by key. |
| src/cachier/cores/memory.py | Implements memory clear_cache_entry removal by key. |
| src/cachier/cores/base.py | Adds abstract clear_cache_entry plus async-thread fallback aclear_cache_entry. |
| src/cachier/core.py | Extends public clear_cache/aclear_cache wrappers to support argument-specific clearing. |
| README.rst | Documents targeted cache clearing usage for sync and async helpers. |
Summary
Closes #53.
Adds argument-specific cache invalidation through the existing cache-management API:
func.clear_cache()keeps clearing all cached entries for the wrapped function.func.clear_cache(*args, **kwargs)now clears only the cache entry matching that call signature.await func.aclear_cache(*args, **kwargs)supports the same targeted behavior for async wrappers.Implementation
clear_cache_entry(key)core primitive plus async fallback support in_BaseCore.selfhandling match normal cache lookups.README.rst.Validation
pytest tests/test_smoke.py::test_clear_cache_for_specific_arguments tests/test_smoke.py::test_clear_cache_for_specific_method_arguments tests/test_async_core.py::TestBasicAsyncCaching::test_clear_cache_for_specific_arguments tests/sql_tests/test_sql_core.py::test_sql_clear_cache_for_specific_arguments tests/mongo_tests/test_mongo_core.py::test_mongo_clear_cache_for_specific_arguments tests/redis_tests/test_redis_core.py::test_redis_clear_cache_for_specific_arguments tests/s3_tests/test_s3_core.py::test_s3_clear_cache_for_specific_arguments -qpytest -m "memory or pickle" -qpytest -m "sql or mongo or redis or s3" -qpytest tests/test_typing.py -qruff check .git diff --checkdocutils.core.publish_doctreeNotes
python setup.py checkdocsis not runnable in this pyproject-only checkout because there is nosetup.py;collective.checkdocsalso fails under the local Python 3.12 environment due to itsdistutilsimport.