Cache Any Python Object

https://badge.fury.io/py/anycache.svg https://travis-ci.org/c0fec0de/anycache.svg?branch=master https://coveralls.io/repos/github/c0fec0de/anycache/badge.svg https://readthedocs.org/projects/anycache/badge/?version=2.0.4 https://codeclimate.com/github/c0fec0de/anycache.png https://img.shields.io/pypi/pyversions/anycache.svg https://landscape.io/github/c0fec0de/anycache/master/landscape.svg?style=flat https://img.shields.io/badge/code%20style-pep8-brightgreen.svg https://img.shields.io/badge/code%20style-pep257-brightgreen.svg

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.

Set a persistent cache directory to preserve the result between multiple python runs:

>>> 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.