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.2.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

anycache-2.2.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: anycache-2.2.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.0 Linux/6.5.0-1025-azure

File hashes

Hashes for anycache-2.2.0.tar.gz
Algorithm Hash digest
SHA256 342ca6bf952f1b62f8725c92b50244f9ef6d0eb1547df768fe2ea2aa429f5c44
MD5 54bcd67c8b20cbf0f8d780a49c10e685
BLAKE2b-256 1226012addbbe17a2a26ace080f391a7ce3a45ed12a908846135afd8202a488b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: anycache-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.0 Linux/6.5.0-1025-azure

File hashes

Hashes for anycache-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4c23284b33bab5f7f46c5d6f024025b944c8a223eb8638f497b68c9913c8922
MD5 dece21544ca229333d3c5f2b3568c6f9
BLAKE2b-256 3ff47b2e6f8f2060ce5ee349c3ccc6eba2ae91c01ad4c428c0965fa7bc3bb6d2

See more details on using hashes here.

Supported by

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