Skip to content

tianiste/caching-proxy-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Caching Proxy CLI

A simple CLI tool written in Go that runs an HTTP caching proxy server.
The proxy forwards requests to an origin server, caches responses, and serves cached responses for repeated requests.


Features

  • Forward HTTP requests to an origin server
  • Cache responses in memory
  • Serve cached responses on repeated requests
  • Add an X-Cache header to indicate cache status:
    • X-Cache: MISS – response fetched from the origin server
    • X-Cache: HIT – response served from cache
  • Thread-safe cache using sync.RWMutex
  • Simple command-line interface

Requirements

  • Go 1.20 or newer

Installation

Clone the repository and build the project:

git clone https://github.com/your-username/caching-proxy-cli.git
cd caching-proxy-cli
go build

Usage

Start the caching proxy server

go run cmd/main.go --port 3000 --origin http://dummyjson.com

This starts the proxy server on port 3000 and forwards requests to http://dummyjson.com.

Example Request:

curl -i http://localhost:3000/products
  • First request: X-Cache: MISS
  • Second request: X-Cache: HIT

Clear the cache

./caching-proxy-cli --clear-cache

Cache Behavior

  • Only GET and HEAD requests are cached
  • Cache key is based on HTTP method and request path + query
  • Non-cacheable requests are always forwarded to the origin server

Notes

  • Cache is only in memory
  • No TTL or size limit

Project Idea

About

A simple CLI tool written in Go that runs an HTTP caching proxy server.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages