Caching decorator

class dlutils.cache(function)[source]

Bases: object

Caches return value of a functions.

Given a function with no side effects, it will compute sha256 hash of passed arguments and use that hash to retrieve saved pickle.

Note

Passed arguments must be picklable.

If you change function, or do any other change that invalidates previously saved caches you will need to delete them manually

Results are saved to ‘.cache’ folder in current directory.

Parameters

function (function) – fucntions to be called.

Example

@dlutils.cache
def expensive_function(x):
    for i in range(12):
        x = x + x * x
    return x