A lightweight caching proxy server written in Go that caches responses from origin servers. It can be used to reduce load on the origin server and improve response times for repeated requests.
- Forward requests to origin server
- Cache responses for subsequent requests
- Cache hit/miss indicators via headers
- CLI tool with configuration options
- Cache clearing functionality
- Thread-safe implementation
- Go 1.21 or higher
- Git
- Clone the repository
git clone https://github.com/letsmakecakes/caching-proxy.git
cd caching-proxy
- Build the binary
go build -o caching-proxy cmd/caching-proxy/main.go
The basic syntax for starting the proxy server is:
./caching-proxy --port <port_number> --origin <origin_url>
Example:
./caching-proxy --port 3000 --origin http://dummyjson.com
This will start the proxy server on port 3000 and forward requests to http://dummyjson.com.
--port
: Port number for the proxy server (default: 3000)--origin
: Origin server URL (required)--clear-cache
: Clear the cached responses
To clear the cache:
./caching-proxy --clear-cache
- Start the proxy server:
./caching-proxy --port 3000 --origin http://dummyjson.com
- Make a request to the proxy server:
# First request (cache miss)
curl -v http://localhost:3000/products/1
# Second request (cache hit)
curl -v http://localhost:3000/products/1
- Check the
X-Cache
header in the response:
X-Cache: MISS
indicates the response came from the origin serverX-Cache: HIT
indicates the response came from the cache
You can use Apache Benchmark (ab) to test the performance improvement with caching:
# Install Apache Benchmark
# On Ubuntu/Debian:
sudo apt-get install apache2-utils
# On macOS:
brew install apache2
# Test without cache (first request)
ab -n 100 -c 10 http://localhost:3000/products/1
# Test with cache (second request)
ab -n 100 -c 10 http://localhost:3000/products/1
Compare the response times between cached and non-cached requests.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.