Skip to main content

Cache any python object to file using improved pickling

Project description

https://badge.fury.io/py/anycache.svg https://img.shields.io/pypi/dm/anycache.svg?label=pypi%20downloads https://readthedocs.org/projects/anycache/badge/?version=latest https://coveralls.io/repos/github/c0fec0de/anycache/badge.svg https://readthedocs.org/projects/anycache/badge/?version=2.1.0 https://img.shields.io/pypi/pyversions/anycache.svg https://img.shields.io/badge/code%20style-pep8-brightgreen.svg https://img.shields.io/badge/code%20style-pep257-brightgreen.svg https://img.shields.io/badge/linter-pylint-%231674b1?style=flat https://img.shields.io/badge/code%20style-black-000000.svg https://img.shields.io/github/contributors/c0fec0de/anycache.svg https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square https://img.shields.io/github/issues-pr/c0fec0de/anycache.svg https://img.shields.io/github/issues-pr-closed/c0fec0de/anycache.svg

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, 5)
  Calcing 8 + 5 = 13
13
>>> myfunc(8, 5)
13

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.

Installation

To install the anycache module run:

pip install anycache

If you do not have write-permissions to the python installation, try:

pip install anycache --user

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anycache-2.3.0.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

anycache-2.3.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file anycache-2.3.0.tar.gz.

File metadata

  • Download URL: anycache-2.3.0.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.5.15

File hashes

Hashes for anycache-2.3.0.tar.gz
Algorithm Hash digest
SHA256 ee13c4c5dd1b553186011c219402c0a334e2c1d28607677c69c82b78b34eef1b
MD5 d2fa17db66b8179c247b694cc419e3b8
BLAKE2b-256 55c62b0bef0b987cd62b96f5d32f697fc6d08da3e77e61f9b3342944630afb5d

See more details on using hashes here.

File details

Details for the file anycache-2.3.0-py3-none-any.whl.

File metadata

  • Download URL: anycache-2.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.5.15

File hashes

Hashes for anycache-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e96ce545b3582ee73a4a36fc3de7e2c55f02a3fa23a9b9d8a384f86b719fc367
MD5 2d158cd62cc3c8fc22b9b8f59204c8a9
BLAKE2b-256 05de5bcdb3592b3bd13de3b33baeff3f3bca532ccf7b8a2ca99b0b800e236d1b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page