Skip to content

blessme247/caching-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Caching Proxy CLI

A simple CLI-based caching proxy server that forwards requests to an origin server and caches responses in-memory for improved performance.


✨ Features

  • In-memory caching with TTL support
  • Cache HIT / MISS detection via logs and headers
  • Forwards requests to any origin server
  • Caches only GET and HEAD requests
  • Preserves response headers and status codes
  • Easy to test with curl or browser

📦 Installation

Clone the repo and install dependencies:

pnpm install

🛠️ Development

Run the CLI in development mode:

pnpm dev --port 3000 --origin https://example.com

🏗️ Build

Compile the project:

pnpm build

🏗️ Link

Link the cli globally:

pnpm link --global

🚀 Usage

After building and linking globally, run:

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

Example:

caching-proxy --port 3000 --origin https://jsonplaceholder.typicode.com

🧪 Testing Cache Behavior

Send requests to your proxy:

curl -i http://localhost:3000/posts
  • First request → 🔴 Cache MISS
  • Subsequent requests → 🟢 Cache HIT

Check response headers:

x-cache: HIT | MISS

⏱️ Cache TTL

  • Default TTL: 50 seconds
  • After expiration, cache is invalidated and refreshed

⚠️ Notes

  • Cache is stored in-memory (cleared on server restart)
  • Only successful responses (2xx - 3xx) are cached
  • Non-GET/HEAD requests bypass cache

📄 License

MIT

About

A simple CLI-based caching proxy server that forwards requests to an origin server and caches responses in-memory for improved performance.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors