skillfed

cache-to-disk

Local disk caching decorator for python function.

cache-to-disk v2.0.0 110.6K downloads/30d#12,448 on PyPI35
Permissive license DORMANT released

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-disk

uv

uv add cache-to-disk

poetry

poetry add cache-to-disk

Installing 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

License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3

Tags

disk caching decoratorfunction result cachingpickle cache to filepersistent function cacheauto-expiring cachelocal disk cache python
cachingpersistencememoization

More Software Development packages