arsenal.cache package

Submodules

arsenal.cache.lazy module

class arsenal.cache.lazy.lazy(func)[source]

Bases: object

Lazily load a property defined by a method. The method wrapped is called at most once to retrieve the result and the result is reused. If the method is a generator, the value is stored as a list.

Note: instances must have a __dict__ attribute in order for this property to work, i.e. no ‘__slots__’ class attribute.

Implementation detail: this is not implemented as a data descriptor so that we can completely avoid the function call overhead. If one choses to invoke __get__ by hand the property will still work as expected because the lookup logic is replicated in __get__ for manual invocation.

arsenal.cache.memoize module

class arsenal.cache.memoize.ShelfBasedCache(func, key, None_is_bad=False)[source]

Bases: object

cache a function’s return value to avoid recalulation and save cache in a shelve.

class arsenal.cache.memoize.memoize(func)[source]

Bases: object

cache a function’s return value to avoid recalulation

class arsenal.cache.memoize.memoize_persistent(func, filename=None)[source]

Bases: object

cache a function’s return value to avoid recalulation and save the cache (via pickle) at system exit so that it persists.

WARNING: retrieves cache for functions which might not be equivalent
if a revision is made to the code which is used to compute it.
get_cached(*args)[source]

If result is cached return it, otherwise return None.

load()[source]
save()[source]
arsenal.cache.memoize.persistent_cache(key=<function <lambda>>, None_is_bad=False)[source]
arsenal.cache.memoize.test_memoize()[source]

arsenal.cache.pkl module

Caching with pickle and the file system.

arsenal.cache.pkl.load(filename, default=None, saveit=False, verbose=False)[source]

Load cached item by name, on miss call get function and cached results.

arsenal.cache.pkl.save(filename, val, verbose=False)[source]

Save val so we can load it via load.

Module contents