-
Notifications
You must be signed in to change notification settings - Fork 73
Add feature: call with freshness threshold #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hey Daniel, :) A very cool feature! Thank you for contributing. Please try and solve this. And tag me or @Borda if you need help. Cheers! |
print(f"{test_func(1, 2) = }") | ||
print(f"{test_func(1, 2) = }") | ||
caller_with_freshness_threshold = ( | ||
test_func.caller_with_freshness_threshold( | ||
timedelta(seconds=0.5), | ||
) | ||
) | ||
print(f"{caller_with_freshness_threshold(1, 2) = }") | ||
print(f"{time.sleep(1.0) = }") | ||
print(f"{test_func(1, 2) = }") | ||
print(f"{caller_with_freshness_threshold(1, 2) = }") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are all the prints needed, why just not assert for expected outcomes?
may need some more debugging... 🤔 |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
@Daniel-Chin are you still working on it? 🦩 |
* Add feature: call with freshness threshold (#262) * 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]> * fixin things up * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix max_age bug * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixes * change max_age condition to strictly smalled * add a short sleep on test_max_age_zero * more sleep * neg max age means cached values are considered stale * some renaming * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * one of the max_age tests needs debugging * sleep for neg max_age test * Update src/cachier/core.py Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Daniel Chin <[email protected]> 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: Copilot <[email protected]>
The feature
In addition to specifying shelf life at storage time, this supports specifying max age at retrieval time.
Motivations
This is useful in interactive projects / data science notebooks.
I personally came to need this when building a cachable API client for Semantic Scholar. (Who knows when's the next groundbreaking paper? I only know how much cache to trust in hindsight.)
How to use
Refer to the test:
Anecdote
can in fact be further reduced to
(how fun!) but then how do you apply
wraps(func)
to type hint it? I haven't the faintest.