Caching Proxy
A high-performance CLI tool that acts as a caching reverse proxy server. It reduces repeated server hits by reusing cached disk responses.It will forward requests to the actual server and cache the responses on the disk. If the same request is made again, it will return the cached response instead of forwarding the request to the server.
Table of Contents
Features
- Reverse Proxy: Seamlessly forwards requests to any specified origin server.
- Disk-Based Caching: Caches HTTP responses locally on disk (JSON format) for persistence.
- Smart Caching Logic: Uses a deterministic key generation strategy based on the request method, URL, and headers.
- Cache Management: Includes built-in commands to clear the cached data.
- CLI Configurable: Easily configure port, origin, cache location, and logging levels via command-line flags.
- Concurrent & Safe: Designed to handle concurrent requests safely.
Getting Started
Prerequisites
- Go: You need to have Go installed (version 1.18 or later recommended). Download Go.
- Make: (Optional) For using the provided Makefile.
Installation
- Clone the repository:
git clone https://github.com/kpraveenkumar19/caching-proxy cd caching-proxy - Build the project:
Using Make:
make buildOr using Go directly:
go build -o bin/caching-proxy ./cmd/caching-proxyThis will create the executable binary in the
bin/directory.
Usage
Run the proxy server by specifying the port to listen on and the origin server to forward requests to.
Command Line Options
The caching-proxy tool supports the following flags:
| Flag | Description | Default |
|---|---|---|
--port |
Required. Port for the caching proxy to listen on. | 3000 |
--origin |
Required. Origin server base URL (e.g., http://example.com). |
"" |
--cache-dir |
Directory for on-disk cache storage. | OS user cache dir or .cache/caching-proxy |
--clear-cache |
Clear the cache directory and exit. | false |
--log-level |
Set logging level (info or debug). |
info |
--version |
Print the version and exit. | false |
Examples
1. Start the proxy server:
Forward requests from port 3000 to http://dummyjson.com:
./bin/caching-proxy --port 3000 --origin http://dummyjson.com
To Start with a custom cache directory and debug logging:
./bin/caching-proxy --port 3000 --origin http://dummyjson.com --cache-dir ./my-cache --log-level debug
2. Make a request to the proxy:
curl -v http://localhost:3000/products
First request: You should see X-Cache: MISS.
Second request: You should see X-Cache: HIT.
3. Clear the cache:
Clears the cache in the specified cache directory
./bin/caching-proxy --clear-cache --cache-dir ./my-cache
Clears the cache in the default OS user cache directory
./bin/caching-proxy --clear-cache
example logs :

Contributing
Contributions are welcome! If you’d like to contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix
- Commit your changes and Push to the branch
- Open a Pull Request.