A simple CLI tool that starts a caching proxy server, forwarding requests to an origin server, caching responses for future requests and returning that responses.
- Caches responses from the origin server.
- Returns cached responses when the same request is made.
- Adds
X-Cacheheaders to indicate if the response is from the cache (HIT) or the origin server (MISS). - Provides a command to clear the cache.
- Node.js (version 14 or higher)
Clone the repository and navigate to the project directory:
$ git clone <repository-url>
$ cd caching-proxyInstall dependencies:
$ npm installInstall caching-proxy cli globally:
$ npm install -g .Run the following command to start the server:
$ caching-proxy --port <number> --origin <url>Example:
$ caching-proxy --port 3000 --origin http://dummyjson.comThe server will start on the specified port and forward requests to the specified origin server.
After starting the server, you can make requests to:
$ curl http://localhost:3000To clear the cache, run:
$ caching-proxy --clear-cacheX-Cache: HIT- The response was returned from the cache.X-Cache: MISS- The response was fetched from the origin server and then cached.
- When a request is made, the server checks if the response for that request exists in the cache.
- If it does, it returns the cached response with the
X-Cache: HITheader. - If it doesn't, it forwards the request to the origin server, caches the response, and returns it with the
X-Cache: MISSheader.
You can find details of this project here.