Metadata-Version: 2.4
Name: ttlru
Version: 0.1.0
Summary: functools.lru_cache with TTL support and async compatibility.
License: MIT License
         
         Copyright (c) 2026 Arman
         
         Permission is hereby granted, free of charge, to any person obtaining a copy
         of this software and associated documentation files (the "Software"), to deal
         in the Software without restriction, including without limitation the rights
         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         copies of the Software, and to permit persons to whom the Software is
         furnished to do so, subject to the following conditions:
         
         The above copyright notice and this permission notice shall be included in all
         copies or substantial portions of the Software.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         SOFTWARE.
License-File: LICENSE
Keywords: cache,lru,ttl,async,decorator
Author: al2m4n
Author-email: al2m4n@gmail.com
Requires-Python: >=3.9,<4.0
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Project-URL: Issues, https://github.com/al2m4n/ttlru/issues
Project-URL: Repository, https://github.com/al2m4n/ttlru
Description-Content-Type: text/markdown

# ttlru

`functools.lru_cache` with TTL support and async compatibility — a single decorator for both sync and async functions.

## Install

```
pip install ttlru
```

## Usage

```python
from ttlru import ttl_cache

# Works for both sync and async — TTL=-1 means never expire (default)
@ttl_cache(ttlru_ttl=60, ttlru_maxsize=256)
def fetch_user(user_id: int):
    ...

@ttl_cache(ttlru_ttl=30)
async def fetch_remote(url: str):
    ...

# No parens — uses defaults (no expiry, maxsize=128)
@ttl_cache
def compute(x):
    ...

# Cache management (mirrors functools.lru_cache)
fetch_user.cache_clear()
fetch_user.cache_info()  # CacheInfo(hits=…, misses=…, maxsize=…, currsize=…)
```

## Parameters

All decorator keyword arguments use the `ttlru_` prefix so they never clash
with parameters of the decorated function (e.g. a function that has its own
`ttl` or `config` parameter).

| Parameter | Default | Description |
|-----------|---------|-------------|
| `ttlru_ttl` | `-1` | Seconds before entry expires. `-1` = never expire. |
| `ttlru_maxsize` | `128` | Max entries. `None` = unlimited, `0` = no caching. |
| `ttlru_typed` | `False` | Cache `f(3)` and `f(3.0)` separately when `True`. |
| `ttlru_config` | global | `CacheConfig` instance for `enabled` flag and telemetry. |

## Telemetry

```python
from ttlru import set_telemetry_provider, MetricsTelemetryProvider

set_telemetry_provider(MetricsTelemetryProvider(my_otel_counter))
```

Built-in providers: `LoggingTelemetryProvider` (default, DEBUG level), `MetricsTelemetryProvider`, `NoOpTelemetryProvider`.

