--- id: cachier version: "4.2.0" 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) license_treatment: permissive maintenance: active --- # cachier — Persistent, stale-free, local and cross-machine caching for Python functions. License: permissive · Maintenance: active · Downloads: 156.3K/mo ## 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 above — 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 pip install cachier uv add cachier 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_current - Install friction: low - Maintenance: active - Downloads: 156.3K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags function result caching decorator, persistent memoization with expiry, cross-machine cache backends, stale-free function caching, redis mongodb sql caching, local pickle cache decorator, async function caching, memoization, persistence, decorator [View on SkillFed](https://skillfed.io/packages/cachier) · [View on PyPI](https://pypi.org/project/cachier/)