A lightweight HTTP caching proxy built with Python and Flask that forwards client requests to a configurable origin server and caches successful responses. Repeated requests for the same endpoint are served directly from the cache, reducing response time and minimizing unnecessary network traffic.
This project demonstrates core backend development concepts such as HTTP request forwarding, REST APIs, file handling, JSON serialization, command-line interfaces (CLI), caching strategies, and Git version control.
- 🌐 Forward HTTP requests to any configurable origin server.
- ⚡ In-memory caching for fast repeated responses.
- 💾 Persistent caching using
cache.json. - 📌
X-Cache: HITandX-Cache: MISSresponse headers. - 🛠 Configurable origin URL using the command line.
- 🔌 Configurable server port.
- 🧹 Clear cached responses with a CLI command.
- 📦 Packaged as an installable Python CLI tool.
- 🏠 Simple home route (
/) for testing.
caching-proxy/
│
├── app.py # Main Flask application
├── cache.json # Persistent cache storage
├── pyproject.toml # Project configuration
├── README.md
└── .gitignore
Clone the repository:
git clone https://github.com/your-username/caching-proxy.git
cd caching-proxyCreate a virtual environment:
python -m venv venvActivate it:
venv\Scripts\activatesource venv/bin/activateInstall the project:
pip install -e .Start the proxy:
caching-proxy --origin https://dummyjson.comSpecify a custom port:
caching-proxy --origin https://dummyjson.com --port 8080Clear the cache:
caching-proxy --clear-cacheRequest:
GET http://localhost:5000/posts/1
First request:
X-Cache: MISS
Subsequent requests:
X-Cache: HIT
- Python
- Flask
- Requests
- JSON
- argparse
- Git & GitHub
Building this project helped me understand:
- REST APIs
- HTTP request forwarding
- Response caching
- JSON file handling
- Flask routing
- Command-line argument parsing
- Python packaging
- Git and GitHub workflow
This project can be extended with several production-ready features:
- ⏳ Cache expiration (TTL)
- 🔐 HTTPS support
- 📈 Logging using Python's
loggingmodule - 📦 LRU (Least Recently Used) cache eviction
- 🔄 Support for POST, PUT, PATCH, and DELETE requests
- 📁 Configurable cache file location
- ⚙️ Configuration using environment variables
- 🧪 Unit and integration tests using
pytest
Thanks to roadmap.sh, I sticked to the roadmap for python given by it, learned all things and built this project. Here is the project URL : https://roadmap.sh/projects/caching-server