Minimal persistent memoization cache
Project description
Cachalot
Cachalot is a minimal persistent memoization cache. It provides a decorator, that stores function result for future use. Perfect for heavy computations and I/O operation (such as web requests). On backend, it uses TinyDB for storage.
Features
- Simple usage via decorator
- Persistent caching
- Key expiration
- Maximum cache size, to prevent bloat
Installation
Cachalot requires Python 3.5 or newer to run.
Python package
You can easily install Cachalot using pip:
pip3 install cachalot
Manual
Alternatively, to get the latest development version, you can clone this repository and then manually install it:
git clone git@gitlab.com:radek-sprta/cachalot.git
cd cachalot
python3 setup.py install
Usage
from cachalot import Cache
@Cache()
def expensive_function():
return expensive_calculation()
Advanced usage
from cachalot import Cache
@Cache(path='cache.json', timeout=3600, size=5e3, filesize=1e6, retry=True, renew_on_read=True)
def expensive_function():
return expensive_calculation()
path
: Path to the database file. Defaults to .cache.json.timeout
: How long should the data be cached in seconds. Defaults to 0 (infinite).size
: Maximum number of keys cached. Defaults to 0 (infinite).filesize
: Maximum size of database file in bytes. Defaults to 0 (infinite).retry
: Retry if result is blank. Defaults to False.renew_on_read
: Renew the entry, i.e refresh the entry timestamp on reads. Defaults to True
For more information, see documentation.
Contributing
For information on how to contribute to the project, please check the Contributor's Guide
Contact
incoming+radek-sprta/cachalot@gitlab.com
License
MIT License
Credits
This package was created with Cookiecutter and the python-cookiecutter project template. Inspired by Cashier
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 Cachalot-1.3.2.tar.gz
.
File metadata
- Download URL: Cachalot-1.3.2.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cce947ca3c6a4e2d59c596cd091e1a0bbf25d559e060155f820b2891ff521597 |
|
MD5 | 36459efc948f28cf18b1200eb84da224 |
|
BLAKE2b-256 | 8dea9054708ab3ec5e3dad29b9babccaabdc3fc00b0586d9b879271fdcb4e820 |
Provenance
File details
Details for the file Cachalot-1.3.2-py3-none-any.whl
.
File metadata
- Download URL: Cachalot-1.3.2-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e18c83930632a3ca92365e51e6b944d8e6ca1fd169dc2c42f3f2fe226485c07 |
|
MD5 | 3876e7b656d8078aa0a73dae3e6846e3 |
|
BLAKE2b-256 | 1a87152c1bdfd2c7998999e28aa42195bb83a3d305c5f796b16ee865c55ec1ec |