Metadata-Version: 2.4
Name: cacheproxy-byiambaka-v2
Version: 0.1.1
Summary: A reverse proxy with redis cahing
Author: Aryan
License: MIT
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: fastapi>=0.115
Requires-Dist: uvicorn>=0.35
Requires-Dist: typer>=0.16
Requires-Dist: httpx>=0.28
Requires-Dist: redis>=6.2
Requires-Dist: pydantic>=2.11

# CacheProxy

CacheProxy is a simple reverse proxy that caches HTTP `GET` responses in Redis. The goal of the project is to reduce response times for repeated requests while keeping the proxy transparent to the client.

I built this project to learn how reverse proxies work, how HTTP caching is implemented, and how Redis can be used to improve API performance.

---

## Features

- Caches successful `GET` requests in Redis
- Adds `Cache: HIT` and `Cache: MISS` headers to every response
- Stores binary responses safely using Base64 encoding
- `/refresh` endpoint to clear the cache
- Configurable through CLI arguments and environment variables
- Handles response headers correctly to avoid browser decoding issues

---

## Installation

```bash
pip install cacheproxy-byiambaka-v2
```

---

## Requirements

- Python 3.10+
- Redis

By default CacheProxy looks for Redis on:

```
Host : localhost
Port : 6379
DB   : 0
```

If your Redis server is running somewhere else, configure it using environment variables.

### Linux / macOS

```bash
export REDIS_HOST=127.0.0.1
export REDIS_PORT=6379
export REDIS_DB=0
```

### Windows

```cmd
set REDIS_HOST=127.0.0.1
set REDIS_PORT=6379
set REDIS_DB=0
```

---

## Running the Proxy

Start the proxy by providing the origin server.

```bash
cacheproxy --origin https://dummyjson.com --port 3000
```

The proxy will start on

```
http://localhost:3000
```

Any request sent to the proxy will be forwarded to the origin server.

---

## Example

Request

```
GET http://localhost:3000/products/1
```

First request

```
Cache: MISS
```

The proxy fetches the response from the origin server and stores it in Redis.

Second request

```
Cache: HIT
```

This time the response is served directly from Redis.

---

## Clearing the Cache

To clear all cached responses:

```bash
curl -X POST http://localhost:3000/refresh
```

Response:

```json
{
  "message": "cache cleared"
}
```

---

## Performance

I measured the proxy using 500 requests against the DummyJSON API.

| Request | Average Time |
|---------|-------------:|
| Cache MISS | 244 ms |
| Cache HIT | 1.09 ms |

Repeated requests were approximately **223× faster** when served from Redis.

---



## Tech Stack

- Python
- FastAPI
- Typer
- HTTPX
- Redis
- Uvicorn
- Pydantic

---



## License

MIT
