cache-to-disk
Local disk caching decorator for python function.
What it is and what it does
cache_to_disk is a Python decorator that persists function results to disk as pickled files instead of holding them in memory. It's designed for functions that are expensive to run and produce large return values—cases where in-memory caching would be wasteful. Each cached result is keyed by the function's arguments, so different argument combinations trigger fresh execution. You specify a cache lifetime in days; after that period, the cached file is deleted on the next module import.
The package provides three main functions: the @cache_to_disk(n_days) decorator itself, a delete_disk_caches_for_function() utility to manually invalidate a function's cache, and a cache_info() method to inspect hit/miss statistics. It also supports a NoCacheCondition exception to prevent caching in error scenarios while still returning a partial result.
Use it for:
- Cache expensive data-processing pipelines that return large objects for days at a time.
- Avoid re-querying slow external APIs or databases when the same arguments are used within a cache window.
- Store intermediate results from long-running computations without consuming RAM.
- Manually invalidate cached results when a function's logic changes or external data is updated.
- Track cache performance with cache_info() to understand hit rates and identify optimization opportunities.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A decorator that caches function results to disk with pickle serialization and automatic expiration based on a configurable number of days.
Yes, if you need simple, argument-aware disk caching for expensive functions and can accept dormant maintenance. The package is permissive-licensed, has no dependencies, and installs easily. However, the last update was in 2021—if you need active support, bug fixes, or compatibility with future Python versions, consider alternatives or be prepared to maintain a fork.
Install
cache-to-disk on PyPI
pip
pip install cache-to-diskuv
uv add cache-to-diskpoetry
poetry add cache-to-diskInstalling cache-to-disk
Before you install
Low install friction with no runtime dependencies. Maintenance is dormant—last release was 2021-12-07 and last commit 2023-12-29, so expect no active support or updates.
License in practice
MIT license (permissive) means you can use, modify, and distribute this package freely with minimal restrictions.
Quickstart
pip install cache-to-disk
from cache_to_disk import cache_to_disk
@cache_to_disk(3)
def my_function():
return [i * j for i in range(10000) for j in range(i)]
result = my_function() # Cached for 3 days
Verify before relying
- Whether pickle serialization is safe for untrusted function return values or if there are known deserialization risks.
- Performance characteristics when caching large objects or handling concurrent access to the same cache files.
- Compatibility with modern Python versions beyond what the unspecified python_support indicates.
Package facts
| License | not declared (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 1,711 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 110,646/month — #12,448 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: cache_to_disk-2.0.0-py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
cachierCachier is a decorator that adds persistent,…
permissive · top 15,000 on PyPI
shelved-cacheWraps cachetools cache implementations with…
permissive · top 5,000 on PyPI
kleptoklepto provides multiple caching algorithms…
permissive · top 15,000 on PyPI
django-memoizeCaches function and method results in Django…
permissive · top 15,000 on PyPI
expiringdictExpiringDict is an ordered dictionary that…
permissive · top 5,000 on PyPI
memoizationDecorator-based function result caching with…
permissive · top 5,000 on PyPI
cached_methodProvides a method-level caching decorator that…
permissive · top 15,000 on PyPI
onecacheOneCache provides LRU-based caching decorators…
permissive · top 15,000 on PyPI
flexcacheCaches the results of expensive computations to…
permissive · top 5,000 on PyPI
diskcacheDiskCache provides a pure-Python disk-backed…
permissive · top 1,000 on PyPI