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.
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:
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 thetest.json
file.