Cache any python object to file using improved pickling
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 342ca6bf952f1b62f8725c92b50244f9ef6d0eb1547df768fe2ea2aa429f5c44 |
|
MD5 | 54bcd67c8b20cbf0f8d780a49c10e685 |
|
BLAKE2b-256 | 1226012addbbe17a2a26ace080f391a7ce3a45ed12a908846135afd8202a488b |
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4c23284b33bab5f7f46c5d6f024025b944c8a223eb8638f497b68c9913c8922 |
|
MD5 | dece21544ca229333d3c5f2b3568c6f9 |
|
BLAKE2b-256 | 3ff47b2e6f8f2060ce5ee349c3ccc6eba2ae91c01ad4c428c0965fa7bc3bb6d2 |