Skip to content

Manohar-1/caching-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Caching Proxy

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.


✨ Features

  • 🌐 Forward HTTP requests to any configurable origin server.
  • ⚡ In-memory caching for fast repeated responses.
  • 💾 Persistent caching using cache.json.
  • 📌 X-Cache: HIT and X-Cache: MISS response 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.

📂 Project Structure

caching-proxy/
│
├── app.py              # Main Flask application
├── cache.json          # Persistent cache storage
├── pyproject.toml      # Project configuration
├── README.md
└── .gitignore

⚙️ Installation

Clone the repository:

git clone https://github.com/your-username/caching-proxy.git
cd caching-proxy

Create a virtual environment:

python -m venv venv

Activate it:

Windows

venv\Scripts\activate

Linux / macOS

source venv/bin/activate

Install the project:

pip install -e .

🚀 Usage

Start the proxy:

caching-proxy --origin https://dummyjson.com

Specify a custom port:

caching-proxy --origin https://dummyjson.com --port 8080

Clear the cache:

caching-proxy --clear-cache

📖 Example

Request:

GET http://localhost:5000/posts/1

First request:

X-Cache: MISS

Subsequent requests:

X-Cache: HIT

🛠 Technologies Used

  • Python
  • Flask
  • Requests
  • JSON
  • argparse
  • Git & GitHub

📚 What I Learned

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

💡 Possible Future Improvements

This project can be extended with several production-ready features:

  • ⏳ Cache expiration (TTL)
  • 🔐 HTTPS support
  • 📈 Logging using Python's logging module
  • 📦 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

📜 License

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

About

This project caches responses of HTTP requests. When a client access specific endpoint, the request gets send to the server, and server sends back a response to the client. My project caches this response. So, it reduces waiting time for the client if they repeatedly accessing the same endpoint.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages