Minimal persistent memoization cache
Project description
Cachalot
![Coverage report](https://pypi-camo.freetls.fastly.net/b8cb6ade013e730bae977ec1832d186074624683/68747470733a2f2f6769746c61622e636f6d2f726164656b2d73707274612f63616368616c6f742f6261646765732f6d61737465722f636f7665726167652e737667)
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=5000)
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 86400 (1 day).size
: Maximum number of keys cached. Defaults to 10000.
For more information, see documentation.
TODO
- Test suite
- Optionally retry if blank data is returned
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.