cachier
Persistent, stale-free, local and cross-machine caching for Python functions.
What it is and what it does
Cachier wraps Python functions with a decorator that persists their return values across program runs, avoiding redundant computation. It stores cached results using pluggable backends—pickle files by default, but also MongoDB, SQL databases, Redis, S3, or in-memory storage—and automatically invalidates stale entries based on a configurable time window. You can set per-function expiry times, trigger background recalculation of stale values without blocking, and globally enable or disable caching.
The package is designed for functions that take more than a second to execute; it adds roughly 1 millisecond of overhead per call. It handles both sync and async functions, supports thread-safe operation, and works across different Python sessions and machines (when using appropriate backends). Arguments must be hashable or you must provide a custom hash function. Instance methods are cached globally across all object instances, which can be a gotcha if methods depend on instance state.
Use it for:
- Cache expensive API calls or database queries with automatic expiry to balance freshness and performance.
- Avoid recomputing long-running data transformations or ML model inference across multiple script runs.
- Share cached results across different machines or processes using MongoDB, Redis, or S3 backends.
- Implement fuzzy refresh: return stale cached values immediately while recalculating in the background.
- Automatically clean up old cache entries on a schedule to prevent unbounded storage growth.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Cachier is a decorator that adds persistent, expiring caching to Python functions, supporting local pickle files, in-memory storage, MongoDB, SQL databases, Redis, and S3 backends.
Yes. Cachier is actively maintained, has low install friction, carries no known vulnerabilities, and solves a common problem (avoiding redundant expensive function calls) with a simple decorator API. The MIT license is permissive. Choose it if you need persistent caching with expiry and backend flexibility; skip it if you only need transient in-memory caching (use functools.lru_cache instead).
Install
cachier on PyPI
pip
pip install cachieruv
uv add cachierpoetry
poetry add cachierInstalling cachier
Before you install
Low friction: pure Python wheel with three lightweight runtime dependencies (portalocker, pympler, watchdog). Active maintenance with recent commits and 661 repository stars. Requires Python 3.10+.
License in practice
MIT License (permissive): you can use, modify, and distribute cachier freely in commercial and private projects with minimal restrictions, provided you include the original copyright notice.
Quickstart
pip install cachier
from cachier import cachier
import datetime
@cachier(stale_after=datetime.timedelta(days=3))
def expensive_function(arg1, arg2):
return {'arg1': arg1, 'arg2': arg2}
result = expensive_function('x', 'y') # cached for 3 days
Requires Python 3.10 or later. Function arguments must be hashable (immutable built-in types); custom objects or mutable containers need a custom hash_func.
Verify before relying
- Overhead claim of 'around 1 millisecond' per call—actual performance impact depends on backend and system load.
- Thread-safety guarantees across all supported backends—documentation does not detail concurrency behavior for each backend.
- Memory core backend performance and limits under high-volume caching scenarios.
Package facts
| License | MIT License Copyright (c) 2016 Shay Palachy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — portalocker, pympler, watchdog |
| Maintenance | actively maintained — 141 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 156,308/month — #10,788 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: cachier-4.2.0-py3-none-any.whl
Keywords: cache, caching, cross-machine, decorator, local, memoization, mongo, persistent
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
cache-to-diskA decorator that caches function results to…
permissive · top 15,000 on PyPI
python-redis-cacheDecorator-based caching for Python functions…
permissive · top 15,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
cachetoolsProvides memoizing collections and function…
permissive · top 1,000 on PyPI
django-cache-memoizeA decorator that caches function results using…
copyleft · top 15,000 on PyPI
kleptoklepto provides multiple caching algorithms…
permissive · top 15,000 on PyPI
zope.cachedescriptorsProvides decorator-based caching for computed…
unclear · top 15,000 on PyPI
jiterA fast JSON parser that converts bytes into…
permissive · top 1,000 on PyPI
aiohttp-client-cacheAdds transparent request caching to…
permissive · top 15,000 on PyPI