A lightweight Go CLI tool that starts a caching proxy server to forward requests to an origin server and cache the responses. It improves performance by serving cached responses for repeated requests.
- Forward HTTP requests to an origin server
- Cache responses for improved performance
- Custom port configuration
- Cache status indicators in response headers
- Command to clear the cache
- Go 1.18 or higher
go install github.com/HackerManPeter/caching-proxy@latest# Clone the repository
git clone https://github.com/HackerManPeter/caching-proxy.git
# Navigate to the project directory
cd caching-proxy
# Build the project
go build -o caching-proxy
# Move the binary to your PATH (optional)
mv caching-proxy /usr/local/bin/Download the appropriate binary for your operating system from the releases page.
caching-proxy --port <number> --origin <url>--port: The port on which the caching proxy server will run--origin: The URL of the server to which the requests will be forwarded
caching-proxy --port 3000 --origin http://dummyjson.comThis will start the proxy server on port 3000 and forward requests to http://dummyjson.com.
Once the proxy server is running, you can make requests to it using the proxy's address.
curl http://localhost:3000/productsThis request will be forwarded to http://dummyjson.com/products, and the response will be cached.
The proxy adds a header to indicate whether the response came from the cache:
X-Cache: HIT- Response served from cacheX-Cache: MISS- Response fetched from origin server
To clear the cache:
caching-proxy --clear-cache- When a request is received, the proxy checks if the response is already cached
- If cached, it returns the cached response with
X-Cache: HITheader - If not cached, it forwards the request to the origin server, caches the response, and returns it with
X-Cache: MISSheader
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.