A high-performance, concurrent Go-based caching proxy server.
This project implements a CLI tool that acts as a caching proxy. It forwards requests to an origin server, caches the responses in-memory, and serves subsequent requests for the same URL directly from the cache, significantly reducing latency and origin load.
- Concurrent-Safe Caching: Uses
sync.Mutexto ensure thread-safe access to the in-memory cache, allowing the proxy to handle multiple simultaneous requests efficiently. - CLI-Driven Configuration: Easily specify the proxy port and origin server via command-line flags.
- Cache Management: Includes a dedicated flag to clear the cache, allowing for easy manual cache invalidation.
- Cache Headers: Automatically adds
X-Cache: HITorX-Cache: MISSheaders to responses to indicate cache status.
The proxy is built using Go's standard library (net/http), emphasizing simplicity and performance.
- Request Interception: The proxy listens for incoming HTTP requests on the configured port.
- Cache Lookup: It checks its internal map for a cached response for the specific URL.
- HIT: If found, it returns the cached body immediately with an
X-Cache: HITheader. - MISS: If not found, it fetches the resource from the origin server, stores it in the cache for future use, and returns it with an
X-Cache: MISSheader.
git clone https://github.com/belikedeep/caching-proxy-server.git
cd caching-proxy-server
go build -o caching-proxyStart the proxy on port 3000, forwarding to https://api.github.com:
./caching-proxy --port 3000 --origin https://api.github.com# First request (MISS)
curl -i http://localhost:3000/users/belikedeep
# Second request (HIT)
curl -i http://localhost:3000/users/belikedeep./caching-proxy --clear-cache- Memory Management: Currently uses an unbounded in-memory map. For production use, a Least Recently Used (LRU) eviction policy would be implemented to prevent memory exhaustion.
- Timeout Handling: Implements basic error handling for origin server connectivity.
- Scalability: The use of Go's
http.ListenAndServeprovides a solid foundation for handling concurrent connections.
MIT - See LICENSE for details.