Skip to main content
caj

Persistent, code-aware caching for JAX functions

CI Codecov Ruff ty uv Publish PyPI PyPI - Python Version

caj is a lightweight persistent cache for JAX-based functions. It stores computation results on disk and reuses them even across Python sessions, avoiding repeated expensive computations.

Unlike caches based only on function arguments, caj also uses JAX's traced computation to identify cached results. Changes to a function's computation—including changes in any other functions it calls—automatically invalidate the corresponding cached results.

import caj
import jax
import jax.numpy as jnp


@caj.cache
@jax.jit
def compute(x):
    return jnp.linalg.eigvalsh(x)


x = jnp.eye(1000)

y = compute(x)  # First call computes and caches the result
y = compute(x)  # Following calls just load the cached result

Installation

Install caj from PyPI:

pip install caj

Usage

Simply decorate a JAX-based function with @caj.cache:

import caj


@caj.cache
@jax.jit
def f(x): ...

Note: adding @jax.jit is optional. If @jax.jit is used, it should be placed below @caj.cache (as the latter is not itself JIT-compatible). It is recommended to use @jax.jit for performance, since functions that are not JIT-compatible will generally not work with @caj.cache either.

By default, caj stores results in a per-user cache directory, with a shared size limit of 1 GB.

To use a custom directory:

@caj.cache(dir=".cache")
def f(x): ...

The maximum cache size can also be configured:

@caj.cache(dir=".cache", max_bytes=2_000_000_000)
def f(x): ...

Set max_bytes=None for an unlimited cache:

@caj.cache(dir=".cache", max_bytes=None)
def f(x): ...

When a size limit is enabled, least-recently-used entries are removed as necessary to make room for new results.

How it works

caj identifies cached results using a hash of the traced JAX computation, its input values, and the JAX and jaxlib versions. This allows it to reuse results even across Python sessions while automatically invalidating cached results when the computation changes.

Unlike JAX's persistent compilation cache, which stores compiled executables, caj stores the results of computations themselves.

Metadata

Release files for caj 0.0.4

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

Source distribution (sdist)

Source distribution for caj 0.0.4
File Size Uploaded Provenance Actions
caj-0.0.4.tar.gz 6.2 kB Without provenance Details for caj-0.0.4.tar.gz

Built distribution (wheel)

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

Total release size: 13.3 kB

Release files / caj-0.0.4.tar.gz

Download URL caj-0.0.4.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f5ca1b16b95cf5d1636b04f7999712ef39cce317904e594c4c80a9078eb1fab8
BLAKE2b-256 checksum
How to use checksums
e43fdd945949e75f5584dd50967739a445a9f5f11c06481e92d202ae9c102bf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / caj-0.0.4-py3-none-any.whl

Download URL caj-0.0.4-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d505ba3be856c27bd550080527a6ab2689275f4da30154845783bebb14f5d262
BLAKE2b-256 checksum
How to use checksums
a40d6407d13c016a03f32d785a295afe668d692cc0b423987a4cf208aeffec33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for caj 0.0.4

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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