A simple CLI tool written in Go that runs an HTTP caching proxy server.
The proxy forwards requests to an origin server, caches responses, and serves cached responses for repeated requests.
- Forward HTTP requests to an origin server
- Cache responses in memory
- Serve cached responses on repeated requests
- Add an
X-Cacheheader to indicate cache status:X-Cache: MISS– response fetched from the origin serverX-Cache: HIT– response served from cache
- Thread-safe cache using
sync.RWMutex - Simple command-line interface
- Go 1.20 or newer
Clone the repository and build the project:
git clone https://github.com/your-username/caching-proxy-cli.git
cd caching-proxy-cli
go buildStart the caching proxy server
go run cmd/main.go --port 3000 --origin http://dummyjson.com
This starts the proxy server on port 3000 and forwards requests to http://dummyjson.com.
Example Request:
curl -i http://localhost:3000/products
- First request: X-Cache: MISS
- Second request: X-Cache: HIT
./caching-proxy-cli --clear-cache
- Only GET and HEAD requests are cached
- Cache key is based on HTTP method and request path + query
- Non-cacheable requests are always forwarded to the origin server
- Cache is only in memory
- No TTL or size limit