Skip to main content

Cachalot PyPI version Pipeline status Coverage reportDownloads

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

Manually deleting entries

If you want to manually invalidate an entry, you can calculate the hash of the function call and then pass it the remove method.

key = cache.calculate_hash(len)('teststring')
cache.remove(key)

For more information, see documentation.

Contributing

For information on how to contribute to the project, please check the Contributor's Guide

Contact

mail@radeksprta.eu

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

Metadata

Release files for Cachalot 1.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Cachalot 1.5.0
File Size Uploaded Provenance
Cachalot-1.5.0.tar.gz 8.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for Cachalot 1.5.0
File Interpreter ABI Platform
Cachalot-1.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.0 kB

Release files / Cachalot-1.5.0.tar.gz

Download URL Cachalot-1.5.0.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2dac05118e746f3eb9aea7de20327610b6619e41cb145cb5bfd9098e7f901c43
BLAKE2b-256 checksum
How to use checksums
8d5d1d7d34dc3b60488e9c596013a94c83ce0ad176676b7e3c420716408b02fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.10

Release files / Cachalot-1.5.0-py3-none-any.whl

Download URL Cachalot-1.5.0-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
426a42d966c624b3524d53aaabf1438373168f78b2f1123283fdb20470a37432
BLAKE2b-256 checksum
How to use checksums
4ddf504ed88cb1f5b03643c61155a04f8027a552d89852990dc3ab9f68ec2d88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.10

Security for Cachalot 1.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page