Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Caching Proxy CLI

A simple command-line interface (CLI) tool written in Go that starts a caching proxy server. It forwards requests to an origin server, caches the responses, and returns cached responses for repeated requests. This project is built as a learning project following the specification from roadmap.sh Caching Server Project.


📌 Features

  • Request Forwarding: Forwards incoming HTTP requests to a specified target origin server.
  • Response Caching: Caches HTTP responses from the origin server so identical subsequent requests are served instantly from cache.
  • Cache Status Headers: Adds an X-Cache HTTP header to responses indicating whether data came from cache (HIT) or origin server (MISS).
  • Cache Clearing: Includes a CLI flag (--clear-cache) to easily clear stored cache entries.
  • Zero External Dependencies: Built entirely using Go's standard library (net/http, flag, fmt, os).

🚀 Getting Started

Prerequisites

  • Go (version 1.20 or higher recommended)

Build & Installation

  1. Clone or navigate to the project directory:

    cd caching-proxy
  2. Build the CLI executable:

    go build -o caching-proxy main.go

💻 Usage

Once built, you can start the server or manage cache using ./caching-proxy (or directly using go run main.go):

Start Caching Proxy Server

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

Example Usage

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

Making Requests

If you make a request to http://localhost:3000/products, the proxy server forwards it to http://dummyjson.com/products and caches the response.

  • First Request (Cache Miss):

    curl -i http://localhost:3000/products

    Header in response:

    X-Cache: MISS
    
  • Second Request (Cache Hit):

    curl -i http://localhost:3000/products

    Header in response:

    X-Cache: HIT
    

Clear Cache

To clear the cache:

caching-proxy --clear-cache

⚡ Response Headers

The caching proxy server attaches an X-Cache header to every response to indicate whether it was served from cache or the origin server:

  • X-Cache: HIT: The response was returned from the local proxy cache.
  • X-Cache: MISS: The response was retrieved from the origin server and saved into cache.

🔗 Reference

About

A CLI tool written in Go that acts as a caching proxy server to forward requests, cache responses, and return X-Cache: HIT/MISS headers.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages