Skip to main content

Minimal persistent memoization cache

Project description

Cachalot PyPI version Pipeline status Coverage report

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, retry=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 86400 (1 day).
  • size: Maximum number of keys cached. Defaults to 10000.
  • retry: Retry if result is blank. Defaults to False.

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cachalot-0.2.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

cachalot-0.2.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file cachalot-0.2.0.tar.gz.

File metadata

  • Download URL: cachalot-0.2.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for cachalot-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c0077b2db2881712cb0c06b81d42fd08222e301ca065c74243167019798f6000
MD5 662625acc4a20f5bce6c2acd5272ee12
BLAKE2b-256 3426f16531f7d77535d68f9519038158ef416e4495c74a5bd30e878fd017f62d

See more details on using hashes here.

Provenance

File details

Details for the file cachalot-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cachalot-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f93927d05661b1062402fcd04c637425bcfc7355322c461b2b870d3136cff1e4
MD5 4f22241e0a156da791260dcbda346749
BLAKE2b-256 8196d1f962789579d14ee9ae0fb6edf1fb25307d1ee068e5f3a24e04e659fc81

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page