cachettl
cachettl is an elegant LRU TTL cache decorator that also works with asyncio. It has the cache_info(), cache_clear() methods and access to the remainingttl property.
What it is and what it does
cachettl is a decorator library that adds time-limited caching to Python functions. It wraps both synchronous and asynchronous functions with an LRU (Least Recently Used) cache that automatically expires entries after a configurable TTL (time-to-live) in seconds. The cache can optionally be bounded by size, and supports type-aware argument caching so that f(3) and f(3.0) are cached separately if desired.
The package provides two decorator variants: the full @cachettl and @async_cachettl decorators expose cache_info() (which returns hits, misses, maxsize, currsize, and remainingttl) and cache_clear() methods; the minimal @cachettl_min and @async_cachettl_min variants omit these introspection features. It is pure Python with no external dependencies, making it lightweight to install and use in any Python 3.7+ environment.
Use it for:
- Cache expensive function results for a fixed duration to reduce redundant computation in web services or data processing pipelines.
- Monitor cache hit/miss ratios and TTL expiration timing via cache_info() to optimize caching parameters.
- Add TTL caching to async I/O-bound functions (e.g., API calls, database queries) without blocking.
- Implement type-aware caching for functions that accept arguments of different types and should treat them as distinct cache keys.
- Replace functools.lru_cache when you need automatic expiration rather than unbounded or LRU-only eviction.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
cachettl provides LRU TTL cache decorators for both synchronous and asynchronous functions, with configurable size limits, type-aware caching, and cache statistics tracking.
Yes, with conditions. The package is stable, MIT-licensed, and has no known vulnerabilities. It fills a genuine niche: simple TTL caching with asyncio support and cache introspection. However, maintenance is dormant (last commit July 2024, no updates since), so adopt it only if you accept that bug fixes or feature requests may not be addressed. For production use in a team, verify that the dormant status aligns with your risk tolerance.
Install
cachettl on PyPI
pip
pip install cachettluv
uv add cachettlpoetry
poetry add cachettlInstalling cachettl
Before you install
Installation friction is high: the package is a pure-Python tarball with no runtime dependencies, but maintenance is dormant—last commit was 2024-07-07 and no activity since. The codebase is stable (Production/Stable classifier) but receives no ongoing updates.
License in practice
MIT license is permissive; you may use, modify, and distribute this package freely with minimal restrictions, provided you include the license notice.
Quickstart
from cachettl import cachettl
import time
@cachettl(ttl=60, maxsize=None, typed=False)
def my_function(arg):
return f"result for {arg}"
result = my_function("test")
info = my_function.cache_info() # Returns (hits, misses, maxsize, currsize, remainingttl)
my_function.cache_clear()
Requires Python 3.7 or later; arguments to cached functions must be hashable.
Verify before relying
- Whether the package handles cache expiration correctly under high concurrency or with very short TTLs.
- Performance characteristics compared to functools.lru_cache or other third-party TTL cache libraries.
- Whether the remainingttl property accounts for clock adjustments or system time changes.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | dormant — 769 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 74,399/month — #14,844 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: cachettl-1.0.4.tar.gz
Keywords: cachettl, cache_ttl, ttlcache, async cache ttl, async_cachettl, functools, lrucache, lru_cache, cache, pure-python, purepython, pure python
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
async-lruAn LRU cache decorator for async functions that…
permissive · top 1,000 on PyPI
memoizationDecorator-based function result caching with…
permissive · top 5,000 on PyPI
onecacheOneCache provides LRU-based caching decorators…
permissive · top 15,000 on PyPI
cachetools-asyncProvides async-aware memoization decorators for…
permissive · top 15,000 on PyPI
async-cacheIn-memory async cache for Python applications…
permissive · top 15,000 on PyPI
asyncacheProvides decorator-based caching for async…
permissive · top 5,000 on PyPI
cachetoolsProvides memoizing collections and function…
permissive · top 1,000 on PyPI
pylruProvides a pure-Python LRU (least recently…
permissive · top 15,000 on PyPI
expiring-dictExpiringDict is a Python dictionary that…
permissive · top 15,000 on PyPI
vercel-cacheProvides runtime cache helpers for Vercel…
permissive · top 5,000 on PyPI