Conversation
* add caller_with_freshness_threshold * fix type * simple test passed * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Apply suggestions from code review * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jirka Borovec <[email protected]> Co-authored-by: Shay Palachy-Affek <[email protected]>
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Contributor
There was a problem hiding this comment.
Pull Request Overview
Adds a per-call freshness threshold (max_age) that forces cache recalculation when a cached value exceeds this age, integrating it with the existing stale_after logic.
- Introduce
max_ageparameter in core wrapper, computing an effective age threshold asmin(stale_after, max_age) - Update tests to cover stricter/looser/zero/negative
max_agescenarios - Document
max_agein README and register a new pytest marker
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_call_with_max_age.py | New tests for various max_age use cases |
| src/cachier/core.py | Core caching logic extended to handle max_age |
| pyproject.toml | Registered maxage pytest marker |
| README.rst | Added Per-call max age section |
Comments suppressed due to low confidence (2)
tests/test_call_with_max_age.py:62
- [nitpick] Add a test where
max_ageexactly equals the decorator'sstale_afterto verify boundary behavior and ensure it meets expectations.
v3 = f(1, max_age=timedelta(seconds=5))
README.rst:243
- Indent the example code block lines by at least four spaces under the
.. code-block:: pythondirective to ensure proper formatting in the rendered docs.
from datetime import timedelta
Member
Author
|
Now this is ready to review (based on @Daniel-Chin 's original PR, but adapted, fixed and thoroughly tested and documented - all, of course, mainly due to cursor). |
Co-authored-by: Copilot <[email protected]>
Borda
approved these changes
Jul 5, 2025
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.
Add the ability to require a minimal degree of freshness from a returned cached value on call/retrieval (unlike setting
stale_afterwhen storing a value in the cache); if the cached value is not fresh enough, a the cached function is called instead.