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
pycachera-4.5.1.tar.gz
(4.6 kB
view hashes)
Built Distribution
Close
Hashes for pycachera-4.5.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23e6df5c8e35bc6fa542f6a5e1b0ab53b30dc46077d0f28d389ecbccc9e9cb13 |
|
MD5 | 1d0aa39c216e7c0675e7c8e0055579e4 |
|
BLAKE2b-256 | bed2d284c9c1efa9f97f0d94cea318bee2bdf9cbb6e224e7ec5cc44c1b164326 |