Metadata-Version: 2.4
Name: fastapi-cache-pro
Version: 0.1.0
Summary: Dead-simple caching for FastAPI — one decorator, done
License: MIT
Project-URL: Repository, https://github.com/shahabRDZ/fastapi-cache-pro
Keywords: fastapi,cache,redis,performance,decorator
Classifier: Framework :: FastAPI
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fastapi>=0.100.0
Dynamic: license-file

<h1 align="center">fastapi-cache-pro</h1>

<p align="center">
  <strong>Dead-simple caching for FastAPI — one decorator, done</strong>
</p>

<p align="center">
  <img src="https://img.shields.io/badge/python-3.10+-blue?logo=python&logoColor=white" />
  <img src="https://img.shields.io/badge/FastAPI-0.100+-009688?logo=fastapi&logoColor=white" />
  <img src="https://img.shields.io/badge/license-MIT-green" />
</p>

---

## Install

```bash
pip install fastapi-cache-pro
```

## Usage

```python
from fastapi import FastAPI, Request
from fastapi_cache_pro import setup_cache, cache

app = FastAPI()
setup_cache()  # uses in-memory by default

@app.get("/users")
@cache(ttl=300)  # cache for 5 minutes
async def get_users(request: Request):
    return await db.get_all_users()  # only called once per 5 min
```

That's it. Second request gets cached response with `X-Cache: HIT` header.

## Redis Backend

```python
import redis.asyncio as redis
from fastapi_cache_pro import setup_cache, RedisBackend

r = redis.from_url("redis://localhost:6379")
setup_cache(RedisBackend(r))
```

## Features

| Feature | Description |
|---------|-------------|
| `@cache(ttl=60)` | Cache any GET endpoint |
| Memory backend | Zero-config, works out of the box |
| Redis backend | For multi-instance deployments |
| Query params | Different params = different cache entries |
| `X-Cache` header | Response tells you HIT or MISS |
| Custom prefix | Namespace your cache keys |
| Pluggable | Write your own backend (Memcached, DynamoDB, etc.) |

## API

```python
# Setup
setup_cache()                          # memory (default)
setup_cache(RedisBackend(redis_client)) # redis

# Decorator
@cache(ttl=60)          # 60 seconds
@cache(ttl=3600)        # 1 hour
@cache(ttl=300, prefix="api")  # custom prefix
```

## How It Works

1. Request comes in → decorator builds cache key from path + query params
2. Key found → return cached JSON, set `X-Cache: HIT`
3. Key not found → call your function, cache result, set `X-Cache: MISS`
4. TTL expires → next request refreshes the cache

## License

MIT
