skillfed

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.

cachettl v1.0.4 74.4K downloads/30d#14,844 on PyPI1
Permissive license MIT DORMANT released

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 cachettl

uv

uv add cachettl

poetry

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 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersIntended Audience :: Information TechnologyIntended Audience :: System AdministratorsLicense :: OSI Approved :: MIT LicenseOperating System :: MacOSOperating System :: Microsoft :: Windows :: Windows 10Operating System :: Microsoft :: Windows :: Windows 11Operating System :: POSIXOperating System :: POSIX :: BSDOperating System :: POSIX :: BSD :: FreeBSDOperating System :: POSIX :: LinuxOperating System :: UnixProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python ModulesTopic :: Utilities

Tags

lru ttl cache decoratortime-limited function cacheasync cache with ttlfunction memoization with expirycache statistics and monitoringttl cache pythonasyncio cache decorator
cachingasynciodecorator

More Libraries packages