--- id: cachettl version: "1.0.4" license: MIT license_treatment: permissive maintenance: dormant --- # 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. License: permissive · Maintenance: dormant · Downloads: 74.4K/mo ## 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 above — 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 pip install cachettl uv add cachettl poetry add cachettl ## Installing 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_current - Install friction: high - Maintenance: dormant - Downloads: 74.4K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags lru ttl cache decorator, time-limited function cache, async cache with ttl, function memoization with expiry, cache statistics and monitoring, ttl cache python, asyncio cache decorator, caching, asyncio, decorator [View on SkillFed](https://skillfed.io/packages/cachettl) · [View on PyPI](https://pypi.org/project/cachettl/)