Metadata-Version: 2.4
Name: simple-redis-cache
Version: 1.0.0
Summary: A library that simplifies working with Redis in Python
Author-email: hotpotato89 <ramilreading@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Hotpotato89
        
        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
Requires-Python: >=3.10
Requires-Dist: redis>=8.0.1
Description-Content-Type: text/markdown

# simple-redis-cache

[![PyPI](https://img.shields.io/badge/PyPI-simple--redis--cache-3776AB?logo=pypi&logoColor=white)](https://pypi.org/project/simple-redis-cache/)
[![Redis](https://img.shields.io/badge/Redis-8.0-DC382D?logo=redis&logoColor=white)](https://redis.io/)
[![uv](https://img.shields.io/badge/uv-0.6-blue?logo=python&logoColor=white)](https://github.com/astral-sh/uv)
[![Pytest](https://img.shields.io/badge/Pytest-9.1-blue?logo=pytest&logoColor=white)](https://pytest.org/)

Простой инструмент для кэширования асинхронных и синхронных функций в Redis.

## Особенности

- **Автоматическая генерация ключей** — ключи создаются на основе имени функции и аргументов
- **Инвалидация по префиксу** — очищайте кэш группами
- **Кастомный JSON-энкодер** — поддерживает `datetime`, `Decimal`, `UUID`, Pydantic-модели
- **Устойчивость к ошибкам** — ошибки Redis не ломают приложение
- **Гибкая настройка** — можно передать свой логгер
- **sync/async поддержка** — можно использовать как для **синхронных**, так и для **асинхронных** функций
- **100% покрытие** - полная уверенность в коде
- **100% `docstrings`** - полная документация функций



## Установка

```bash
pip install simple-redis-cache
```

## Использование:

```python
from simple_redis_cache.sync import Cache  # Синхронный
```

```python
from simple_redis_cache.asyncio import Cache  # Асинхронный
```

## Пример

```python
from redis.asyncio import Redis
from simple_redis_cache import Cache

redis = Redis()
cache = Cache(redis)

@cache.cache(ttl=60, prefix="user")
async def get_user(user_id: int):
    return {"id": user_id, "name": "Alice"}

# Первый вызов — вычисляется, второй — из кэша
r1 = await get_user(1)
r2 = await get_user(1)

# Одинаковый результат
print(r1 == r2)
```

## Инвалидация
```python
await cache.invalidate_cache(prefix="user")
```

## Лицензия
[**MIT**](LICENSE) 
## Автор
[**hotpotato89**](https://github.com/hotpotato89)