Skip to content

Add argument-specific cache clearing#390

Open
shaypal5 wants to merge 3 commits into
masterfrom
codex/clear-cache-args-53
Open

Add argument-specific cache clearing#390
shaypal5 wants to merge 3 commits into
masterfrom
codex/clear-cache-args-53

Conversation

@shaypal5

Copy link
Copy Markdown
Member

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

  • Adds a clear_cache_entry(key) core primitive plus async fallback support in _BaseCore.
  • Implements targeted deletion for memory, pickle, MongoDB, Redis, SQL, and S3 backends.
  • Reuses the existing argument-to-cache-key normalization so positional arguments, keyword arguments, defaults, and method self handling match normal cache lookups.
  • Documents targeted clearing in 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 -q
  • pytest -m "memory or pickle" -q
  • pytest -m "sql or mongo or redis or s3" -q
  • pytest tests/test_typing.py -q
  • ruff check .
  • git diff --check
  • README parsed with docutils.core.publish_doctree

Notes

  • No open repository milestone was available to assign.
  • python setup.py checkdocs is not runnable in this pyproject-only checkout because there is no setup.py; collective.checkdocs also fails under the local Python 3.12 environment due to its distutils import.

@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.95%. Comparing base (422f890) to head (61c86fb).

Additional details and impacted files

Impacted file tree graph

@@           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           
Flag Coverage Δ
local 66.26% <65.11%> (-0.31%) ⬇️
mongodb 39.83% <34.88%> (-0.19%) ⬇️
postgres 41.99% <40.69%> (-0.07%) ⬇️
redis 44.60% <44.18%> (+0.03%) ⬆️
s3 41.16% <37.20%> (-0.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/cachier/core.py 100.00% <100.00%> (ø)
src/cachier/cores/base.py 100.00% <100.00%> (ø)
src/cachier/cores/memory.py 100.00% <100.00%> (ø)
src/cachier/cores/mongo.py 100.00% <100.00%> (ø)
src/cachier/cores/pickle.py 99.66% <100.00%> (+0.01%) ⬆️
src/cachier/cores/redis.py 100.00% <100.00%> (ø)
src/cachier/cores/s3.py 100.00% <100.00%> (ø)
src/cachier/cores/sql.py 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 422f890...61c86fb. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, **kwargs and clear only the matching cache entry when provided.
  • Introduce a core-level primitive clear_cache_entry(key) with an async-compatible aclear_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.

Comment thread src/cachier/cores/pickle.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI & Agents area: agent-workflows Agent instructions, AI-assisted workflow docs, or bot-maintained guidance. area: ci GitHub Actions, pre-commit, codecov, or automation config. area: core-api Decorator API, cache semantics, or public behavior. area: docs README, examples, contributor docs, or repo documentation. area: hashing Hashing, key generation, argument handling, or signatures. area: memory In-memory backend. area: mongo MongoDB backend or MongoDB test services. area: pickle Pickle/file-system backend. area: redis Redis backend or Redis test services. area: s3 S3 backend or boto/moto integration. area: sql SQL/PostgreSQL backend or SQLAlchemy integration. area: tests Test suite, fixtures, coverage, or local test scripts. CI codex documentation enhancement good first issue linting & style source: codex Opened from a Codex-assisted workflow. status: open Currently open. testing and development type: ci GitHub Actions, CI configuration, or automation workflow change. type: docs Documentation-only or documentation-focused change. type: feature Adds or materially changes user-facing functionality. type: tests Tests, fixtures, test coverage, or test data.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clearing cache based on method parameters

2 participants