Cache Any Python Object¶

Cache any python object to file using improved pickling
Getting started¶
To cache the result of a function, use the global unlimited anycache:
>>> from anycache import anycache
>>> @anycache()
... def myfunc(posarg, kwarg=3):
... print(" Calcing %r + %r = %r" % (posarg, kwarg, posarg + kwarg))
... return posarg + kwarg
>>> myfunc(8, 10)
Calcing 8 + 10 = 18
18
>>> myfunc(8, 10)
18
anycache caches nearly any python object. Also lambda statements. It uses Dill as backend. An improved version of pythons build-in pickle.
To preserve the result between multiple python runs, a persistent cache directory needs to be set.
>>> from anycache import anycache
>>> @anycache(cachedir='/tmp/anycache.my')
... def myfunc(posarg, kwarg=3):
... return posarg + kwarg
The AnyCache
object serves additional functions for cache clearing and
size handling.