--- id: onecache version: "0.8.1" license: MIT license_treatment: permissive maintenance: active --- # onecache — Python cache for sync and async code License: permissive · Maintenance: active · Downloads: 725.7K/mo ## 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 above — 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 pip install onecache uv add onecache poetry add onecache ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 725.7K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags python function caching decorator, lru cache async sync, ttl cache with expiration, in-memory cache library, decorator-based caching, caching, lru-cache, async-support [View on SkillFed](https://skillfed.io/packages/onecache) · [View on PyPI](https://pypi.org/project/onecache/)