Cache Proxy is a simple, bare-bones caching proxy server implemented in Go. It serves as a basic solution for caching HTTP requests and responses, using an in-memory map to store the cache.
-
In-Memory Caching:
- The server uses an in-memory map to store cached responses. This approach allows for fast lookups and reduces the time needed to retrieve cached data.
-
Proxy Functionality:
- The server forwards client requests to the target server and caches the responses. If the same request is made again, the server returns the cached response, saving the time and resources of making a new request to the target server.
-
Simple Design:
- This is a minimalistic implementation aimed at demonstrating the core concepts of a caching proxy server. It is not suitable for production use without further enhancements.
go run cmd/cache-proxy/main.go --port <PORT> --origin <ORIGIN_URL>
go run cmd/cache-proxy/main.go --clear-cache
Since the cache is stored in memory, it is limited by the available RAM. For large-scale use cases, consider implementing a more sophisticated caching mechanism that can handle larger datasets or persist the cache to disk.
This implementation does not include a cache eviction policy. The cache will grow indefinitely, which could lead to memory exhaustion in long-running scenarios. Adding an eviction policy like LRU (Least Recently Used) would be a recommended enhancement.
- Cache Persistence: Implementing a mechanism to persist the cache to disk would allow the server to maintain the cache across restarts.
- Cache Expiry: Introducing cache expiry times for the stored responses would ensure that outdated data is not served to clients.
- Concurrency Handling: Enhancing the server to handle concurrent requests more efficiently would improve its performance in multi-client environments.
This is a minimal implementation intended as a starting point for more complex caching proxy solutions.
This Repo serves as a solution to Roadmap.sh Caching Server Problem