Skip to main content

Cachephant

Cachephant is a small python library which caches function output to disk to avoid unnecessary recomputation. It's aimed for use in Jupyter notebooks.

Problem

There's already joblib.Memory and diskcache.memoize. However, they didn't provide the behavior I desired (see table below):

  • Joblib is very conservative and it's cache cannot be reused after restarting the Jupyter kernel. Moreover, unrelated code changes lead to cache invalidation.
  • In contrast, diskcache is very liberal in its cache reuse and doesn't notice function code or signature changes. (This may be great for running a stable web app for weeks, but less idea for data science development.)
uses cache if... joblib diskcache cachephant
Jupyter kernel restarts n y y
same "resolved" arguments n n ! y
some unrelated code changes n y y
some related code changes n y y (n would be ideal but difficult)
function code changes n y ! n
function signature changes raises error y ! n

How to use

import cachephant

cache = cachephant.get_default_cache("/path/to/dir")

@cache
def slow_function():
    time.sleep(10)
    return 3

You can also instantiate cachephant.Cache() and easily pass custom database-, file-, hash-, and evictor-classes.

Non-goals

This library is not meant for high frequency use cases (think hundreds of cache reads/writes per second) and you'll likely see performance issues.

Release files for cachephant 0.2.1

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

Source distribution (sdist)

Source distribution for cachephant 0.2.1
File Size Uploaded
cachephant-0.2.1.tar.gz 6.6 kB Details

Built distribution (wheel)

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

Total release size: 14.0 kB

Release files / cachephant-0.2.1.tar.gz

Download URL cachephant-0.2.1.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
21ed12c9dffb924885c03b81bf4a495ec3817140f5ae07dcff0e790e862dc020
BLAKE2b-256 checksum
How to use checksums
a7f0742d45e3794a9452b9c5da1b710bd3ce86a88c114a2b5e7d17b52aa02e84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.12.2 CPython/3.10.12

Release files / cachephant-0.2.1-py3-none-any.whl

Download URL cachephant-0.2.1-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4db0ec2e87a883295e7b3cf996fe0a45dc88d09b64240b97f9eef24c759d3b45
BLAKE2b-256 checksum
How to use checksums
5fabffd5a6a43cca2ef2892e86b50d7218e11b5bedeb3dd1d7bb39de48b006c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.12.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

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