onecache
Python cache for sync and async code
What it is and what it does
OneCache is a lightweight in-memory caching library that wraps functions with LRU (Least Recently Used) eviction and optional time-to-live expiration. It provides two decorator classes—CacheDecorator for sync functions and AsyncCacheDecorator for async coroutines—allowing you to cache function results without modifying function signatures. The cache automatically evicts the oldest entry when it reaches maxsize, and can optionally expire entries after a specified TTL in milliseconds. You can also set memory size limits and enable thread-safe locking for concurrent access.
The library is designed for straightforward use: decorate a function, configure cache size and TTL, and results are automatically cached and reused on subsequent calls with identical arguments. It supports skipping arguments from the cache key, refreshing TTL on each access, and choosing alternative cache implementations via the cache_class parameter.
Use it for:
- Cache expensive database queries or API calls in web applications to reduce latency and load.
- Memoize computationally intensive calculations in data processing pipelines with automatic expiration.
- Speed up async coroutines by caching results across multiple concurrent requests with TTL-based invalidation.
- Reduce redundant function calls in long-running services where results are valid for a limited time window.
- Implement request-level or session-level caching in frameworks without external cache infrastructure.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
OneCache provides LRU-based caching decorators for both synchronous and asynchronous Python functions, with optional per-entry TTL expiration and configurable memory limits.
Yes. OneCache is a solid choice for lightweight, decorator-based caching in Python applications. It has zero runtime dependencies, is actively maintained, supports modern Python versions (3.8–3.14), carries no security vulnerabilities, and works seamlessly with both sync and async code. Install it if you need simple LRU caching with optional TTL and don't want to manage an external cache service.
Install
onecache on PyPI
pip
pip install onecacheuv
uv add onecachepoetry
poetry add onecacheInstalling onecache
Before you install
Low install friction with no runtime dependencies. Actively maintained as of 2026-02-20, tested across CPython 3.8–3.14 and PyPy 3.9 on Linux, macOS, and Windows.
License in practice
MIT license (permissive) places no restrictions on use, modification, or distribution in proprietary or open-source projects.
Quickstart
from onecache import CacheDecorator, AsyncCacheDecorator
@CacheDecorator(maxsize=512, ttl=None)
def my_function(x):
return x * 2
@AsyncCacheDecorator(maxsize=512)
async def my_async_function(x):
return x * 2
Requires Python 3.8 or later; max_mem_size parameter is ignored on PyPy due to JIT compilation.
Verify before relying
- Performance characteristics and overhead compared to functools.lru_cache or other caching libraries.
- Thread safety guarantees when thread_safe=True is enabled.
- Behavior of refresh_ttl flag and its interaction with concurrent access patterns.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 175 days since the last release |
| First released | |
| Downloads | 725,663/month — #5,220 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: onecache-0.8.1-py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
async-lruAn LRU cache decorator for async functions that…
permissive · top 1,000 on PyPI
cachettlcachettl provides LRU TTL cache decorators for…
permissive · top 15,000 on PyPI
cachetools-asyncProvides async-aware memoization decorators for…
permissive · top 15,000 on PyPI
cacheoutCacheout provides in-memory caching with…
permissive · top 5,000 on PyPI
cachetoolsProvides memoizing collections and function…
permissive · top 1,000 on PyPI
asyncacheProvides decorator-based caching for async…
permissive · top 5,000 on PyPI
cache-to-diskA decorator that caches function results to…
permissive · top 15,000 on PyPI
expiring-dictExpiringDict is a Python dictionary that…
permissive · top 15,000 on PyPI
cacheboxCachebox is a high-performance in-memory…
permissive · top 5,000 on PyPI
pytest-antilruClears functools.lru_cache between pytest test…
permissive · top 15,000 on PyPI