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 https://img.shields.io/pypi/pyversions/anycache.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.1.tar.gz (13.7 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.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for anycache-2.3.1.tar.gz
Algorithm Hash digest
SHA256 462644b1a54186edab9787dfae943bac1b735bb983bba2a9957318a6ca4ea5ec
MD5 1fea85c8f9f37ef7a1b911e1c60a0167
BLAKE2b-256 bc14af30ad16c5d86ee4ffbccdd10dd942dc4af6d2ec5ea3827ebbfee8a6a5f3

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for anycache-2.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 84e6c89a65ce1f21c5c0bd8dd0cd951bd8cb6a98236e54983df65fa4a8fdade9
MD5 0e2088ecec91b3bb42f1816399a3c8aa
BLAKE2b-256 4ed246ce2b6b43100b726c8246732c3408ac60efd2aa6f70853cec83e18d1fda

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