Skip to content
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

Store cached results locally #220

Closed
YHordijk opened this issue Apr 29, 2024 · 0 comments · Fixed by #221
Closed

Store cached results locally #220

YHordijk opened this issue Apr 29, 2024 · 0 comments · Fixed by #221
Assignees
Labels
enhancement New feature or request

Comments

@YHordijk
Copy link
Contributor

Currently we have a number of useful functions in tcutility.cache, but it would be good to be able to store it locally.
I propose we add the tcutility.cache.cache_file decorator. This will cache the results of a function and store it in a .json file.

Example:

@cache_file('test.json')
def test(a, b, c):
    return a + b * c

test(1, 2, 3)  # this will run the function
test(1, 2, 3)  # this will retrieve it
test(1, 4, 3)  # this will run the function
test(1, 2, 3)  # this will retrieve it
test(1, 4, 3)  # this will retrieve it

This script will store results in test.json. When a function call was already made with the same function, args and kwargs it will read it from the test.json file.

@YHordijk YHordijk added the enhancement New feature or request label Apr 29, 2024
@YHordijk YHordijk self-assigned this Apr 29, 2024
@YHordijk YHordijk linked a pull request Apr 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant