A powerfull python caching tool
Project description
PyCachera
A powerful python decorator to cache functions
Installation
In command line:
pip install pycachera
Usage
Import the pycachera as:
from pycachera import cache
For caching a function
@cache()
def sum(a,b):
return a+b
For caching a class attributes.
class Math:
def __init__(self):
pass
@cache()
def sum(a,b):
return a + b
For caching to a specific directory.
@cache(cachefolder='/home/user/scratch')
def sum(a,b):
return a+b
For caching with a specific key
@cache(cachekey='This a custom cache')
def sum(a,b):
return a+b
For printing the info
@cache(verbose=True)
def sum(a,b):
return a+b
While debugging your script if you want to ignore the cached values you can recache
@cache(recache=True)
def sum(a,b):
return a+b
When you use cache with a class attribute, and if you want to consider some attributes of that class for caching,
class Math:
def __init__(self,c):
self.c = c
@cache(extrarg=['c'])
def sum(a,b):
return a + b
To cache a class property,
class math:
def __init__(self,a,b):
self.a = a
self.b = b
@property
@cache(extrarg=['a','b'],verbose=True)
def add(self):
return self.a + self.b
When using mpi4py.MPI,
@cache(with_mpi=True)
def sum(a,b):
return a+b
API
visit pycachera.readthedocs.io
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 pycachera-4.5.1.tar.gz
.
File metadata
- Download URL: pycachera-4.5.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66901d57d2129ed2e16ba1f59261eeb72efe86fbddbe21c7b65491b17504e9f6 |
|
MD5 | 4bf3d9b3d6afd06e63e89f61f3fb7ee2 |
|
BLAKE2b-256 | 3c19dd80801d407514bdb7e3022ed2a65207fa7cc0cfdfb1470389f0ff3b63ba |
File details
Details for the file pycachera-4.5.1-py3-none-any.whl
.
File metadata
- Download URL: pycachera-4.5.1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23e6df5c8e35bc6fa542f6a5e1b0ab53b30dc46077d0f28d389ecbccc9e9cb13 |
|
MD5 | 1d0aa39c216e7c0675e7c8e0055579e4 |
|
BLAKE2b-256 | bed2d284c9c1efa9f97f0d94cea318bee2bdf9cbb6e224e7ec5cc44c1b164326 |