Categorygithub.com/Venukishore-R/caching-proxy
repositorypackage
0.0.0-20241123174249-082e596f4a04
Repository: https://github.com/venukishore-r/caching-proxy.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

Caching Proxy Server

A simple CLI tool that implements a caching proxy server. This server forwards requests to an origin server and caches the responses. If the same request is made again, it returns the cached response instead of forwarding the request to the origin server.

Table of Contents

Features

  • Forward requests to an origin server.
  • Cache responses to improve performance.
  • Return cached responses for repeated requests.
  • Indicate whether the response was served from the cache or the origin server.
  • Clear the cache using a command.

Requirements

  • Go 1.16 or higher

Installation

  1. Clone the repository:
   git clone https://github.com/Venukishore-R/caching-proxy.git
   cd caching-proxy
  1. Make sure you have the necessary dependencies:
   go mod tidy
  1. Install the application:
   make install

It will the run the build and install go command

Usage

To start the caching proxy server, run the following command:

  caching-proxy --port <number> --origin <url>

Example

To start the server on port 3000 and forward requests to http://dummyjson.com, use:

   caching-proxy --port 3000 --origin http://dummyjson.com

Now, if you make a request to http://localhost:3000/products, the caching proxy server will:

  • Forward the request to http://dummyjson.com/products.
  • Return the response along with headers.
  • Cache the response for future requests.

Response Headers

  • If the response is served from the cache: X-Cache: HIT

  • If the response is served from the origin server: X-Cache: MISS

Cache Management

To clear the cache, run the following command:

   curl <YOUR_URL>/clear-cache

Example

To clear the cache, use:

   curl http://localhost:3000/clear-cache

This command will remove all cached responses.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for any suggestions or improvements.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Conclusion

For further insights into building caching servers and to enhance your understanding of the topic, you can visit this roadmap.