skillfed

cachier

Persistent, stale-free, local and cross-machine caching for Python functions.

cachier v4.2.0 156.3K downloads/30d#10,788 on PyPI661
Permissive 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) Active released

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 cachier

uv

uv add cachier

poetry

poetry add cachier

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: PythonProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Other/Nonlisted TopicTopic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python ModulesTopic :: Utilities

Tags

function result caching decoratorpersistent memoization with expirycross-machine cache backendsstale-free function cachingredis mongodb sql cachinglocal pickle cache decoratorasync function caching
memoizationpersistencedecorator

More Libraries packages