cachetools
In-memory memoizing cache collections and decorators for Python, beyond the standard library's lru_cache
Repository Health
Technical Analysis
cachetools provides various memoizing collections and decorators for Python, including variants of the standard library’s @lru_cache function decorator. A cache in this module is a mutable mapping of a fixed maximum size; when full, the cache discards items based on a chosen cache algorithm (LRU, LFU, TTL, FIFO, RR, and more).
The library exposes both cache classes (LRUCache, TTLCache, etc.) that behave as regular dict-like mappings, and @cached/@cachedmethod decorators that wrap functions or methods to transparently memoize their results against any of those cache instances, including thread-safe usage via an explicit lock argument.
What You Get
- Cache classes implementing LRU, LFU, TTL, FIFO, RR, and other eviction algorithms as dict-like mutable mappings
@cachedand@cachedmethoddecorators for memoizing plain functions and instance/class methods- A
keysmodule for building custom cache keys from function arguments (e.g. ignoring specific parameters) - Thread-safe usage support via an explicit
lockargument on the decorators - A
funcmodule offeringfunctools.lru_cache-compatible drop-in decorators backed by cachetools’ cache classes
Common Use Cases
- Memoizing expensive pure-function calls (recursive algorithms, API lookups) with an LRU or TTL bound
- Caching per-instance computed properties or expensive method calls via
@cachedmethod - Rate-limiting external API calls by caching responses for a fixed TTL window
- Replacing ad-hoc dict-based caches with a maintained, size-bounded, thread-safe alternative
Under The Hood
Architecture - The package is organized as a small src/cachetools module: __init__.py (774 lines) defines the cache classes (Cache, LRUCache, LFUCache, TTLCache, FIFOCache, RRCache, etc.) as subclasses of a shared MutableMapping-based base, _cached.py and _cachedmethod.py implement the decorator logic separately for functions vs. methods, and keys.py provides key-generation helpers used by the decorators. Tech Stack - Pure Python with no runtime dependencies, using only the standard library’s collections.abc and time modules; packaged with a standard pyproject.toml/src-layout build. Code Quality - 14 test modules under tests/ cover the individual cache classes and decorators, CI runs via GitHub Actions with Codecov coverage reporting badges shown in the README, and the codebase is stable/mature (mature project per repo-health signals) with infrequent but steady maintenance. API Design - the cache classes are deliberately dict-like (MutableMapping subclasses), so users already familiar with Python dicts can drop them in directly; the @cached(cache=...) decorator mirrors functools.lru_cache’s ergonomics while accepting any cache instance, keeping the public surface small and consistent across eviction strategies.
Used by 16 apps in this directory
agenta
Developer Tools · Devops · AI Development
The open-source LLMOps platform unifying prompt engineering, evaluation, and observability for teams building reliable LLM applications.
Agno
Devops · AI Development · Automation
Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.
Apache Airflow
Data Engineering
Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.
authentik
Authentication · Security
The self-hosted Identity Provider that replaces Okta, Auth0, and Entra ID with a unified SSO platform supporting SAML, OAuth2/OIDC, LDAP, RADIUS, and WebAuthn.
AutoGPT
Automation · Productivity · AI Assistants
Build, deploy, and run autonomous AI agents that automate complex multi-step workflows using a visual block-based graph editor.
Helicone
Monitoring · AI Development · Analytics
An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.
Langflow
AI Agents · AI Development
Build, test, and deploy AI agents and RAG workflows visually with native API and MCP server export.
MLflow
AI Development · Monitoring
The open source AI engineering platform for debugging, evaluating, monitoring, and optimizing production LLMs and agents at scale.
OpenReplay
Analytics
Self-hosted session replay and product analytics suite that lets you see exactly what users do on your web app — without sending data to third parties.