Result Caching
Stores function results so that they are not computed again on repetitive calls of the function with the same arguments. Results can be stored either on disk or in memory.
Quick setup
pip install git+https://github.com/mschrimpf/result_caching
Usage example
from result_caching import store
@store()
def f(a, b):
return a * b
y = f(1, 2) # computed first time, stored on disk
y = f(1, 2) # not computed again, loaded from disk
y = f(1, 3) # computed again, different parameters
By default, results will be stored in ~/.result_caching, this can be
changed through the environment variable RESULTCACHING_HOME.
cache will only hold results in memory and not write them to disk.
Environment variables
| Variable | description |
|---|---|
| RESULTCACHING_HOME | directory to cache results (benchmark ceilings) in, ~/.result_caching by default |
| RESULTCACHING_DISABLE | * '1' to disable loading and saving of results, functions will be called directly |
* 'candidate_models.score_model,model_tools.activations' to disable loading and saving of function identifiers starting with one of the specifiers separated by a comma (e.g. any package or function inside model_tools.activations will not be considered) |
|
| RESULTCACHING_CACHEDONLY | If enabled, raises an error when trying to run a function that does not have its result already cached (follows the same matching rules as RESULTCACHING_DISABLE) |
| RESULTCACHING_FORMAT | storage format for xarray results: pickle (default) or netcdf/nc. netCDF writes a .nc file plus a sidecar .manifest.json recording the class, dtype, shape, schema version and package versions |
| RESULTCACHING_S3_BUCKET | S3 bucket for xarray results. Setting this is what enables the S3 backend — unset means disk only. Requires the s3 extra (pip install result_caching[s3]) |
| RESULTCACHING_S3_PREFIX | key prefix within the bucket, result_caching by default |
| RESULTCACHING_S3_EPOCH | prefix segment for bulk invalidation, 1 by default. Bumping it orphans every existing entry at once, which is cheaper than deleting them when a lifecycle rule will expire them anyway |
| RESULTCACHING_S3_MAX_GB | refuse to write entries larger than this, 50 by default. The size distribution has a long tail — one vision model projects to 146 GB against a p90 of 31 GB — and that tail is most of the storage bill for a fraction of the benefit |
Storage formats
pickle (the default) is fast but tied to the exact pandas/xarray/numpy
versions that wrote it. netcdf is portable across environment upgrades, at the
cost of flattening MultiIndex coordinates on write and rebuilding them on load.
The default is deliberately still pickle so that existing warm caches stay
valid; opt in per environment rather than globally.
Either way an unreadable entry is treated as a miss, never an error — a cache written before a dependency bump is recomputed rather than raising.
S3 backend
Set RESULTCACHING_S3_BUCKET to make xarray results readable and writable
across machines, which is what makes the cache useful for ephemeral containers
where local disk does not survive the job.
Entries are always netCDF on S3 regardless of RESULTCACHING_FORMAT; the data
object is written before its manifest and a read requires the manifest, so
an interrupted write is indistinguishable from a miss and needs no temp-key
dance (S3 PUTs are already atomic).
boto3 is an optional dependency. If it is missing, the backend degrades to "no cache" rather than breaking the import.
Metadata
Release files for result-caching 0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| result_caching-0.5.tar.gz | 22.4 kB | Without provenance | Details for result_caching-0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| result_caching-0.5-py3-none-any.whl | Python 3 | none | any | Details for result_caching-0.5-py3-none-any.whl |
Total release size: 35.4 kB
Release files / result_caching-0.5.tar.gz
| Download URL | result_caching-0.5.tar.gz |
|---|---|
| Size | 22.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
62b43856e5738272e5a06d558541e689178ea7d3ce9d2bd598bec0e9a97258d6
|
|
BLAKE2b-256 checksum How to use checksums |
0eddb491ce8a631e24fd4a142f4899214464bd7a0425765dc87b36fed376cfa5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.14
|
Release files / result_caching-0.5-py3-none-any.whl
| Download URL | result_caching-0.5-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bdf0c9abc81c393871d7dbfa8cfb4fac66e36321482e8e59e6a62d13aa983eb0
|
|
BLAKE2b-256 checksum How to use checksums |
ed8547575004bb9222781100904d0d623aeff1a8f4cd442234c54e13b121a220
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.14
|
Security for result-caching 0.5
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.