Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Proxy Server with Caching

This is a simple proxy server built using Express.js, Node.js, and NodeCache. It forwards incoming requests to an origin server and caches the responses to improve performance and reduce load on the origin server.

Caching Proxy Server

Project from Backend Learning Path - Caching Server

Features

  • Proxy requests to a specified origin server.
  • Cache responses with a configurable Time-to-Live (TTL).
  • Clear the cache using a command-line flag.
  • Configurable via command-line arguments.
  • Supports all HTTP methods and forwards headers, body, and query parameters.

Requirements

  • Node.js (>= 14.x recommended)
  • npm or yarn

Installation

# Install globally
npm install -g .

# Or run directly with
npm start

Usage

Start the proxy server:

caching-proxy --port <number> --origin <url> [--ttl <seconds>]

Example:

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

Clear the cache:

caching-proxy --clear-cache

Options

  • --port, -p: Port to run the proxy server on
  • --origin, -o: Origin server URL to proxy requests to
  • --ttl, -t: Cache TTL in seconds (default: 3600)
  • --clear-cache: Clear the cache and exit
  • --help: Show help

Response Headers

The proxy adds an X-Cache header to indicate cache status:

  • X-Cache: HIT - Response served from cache
  • X-Cache: MISS - Response from origin server

Features

  • Configurable Cache TTL: Allows setting a time-to-live (TTL) for cached responses via command-line arguments.
  • Cache Clearing: Supports a --clear-cache flag to flush all cached data and exit.
  • Command-Line Configuration: Flexible command-line options for setting port, origin, TTL, and other runtime parameters.
  • Full HTTP Method Support: Handles all HTTP methods, including GET, POST, PUT, DELETE, and more.
  • Error Handling: Provides meaningful error messages for bad gateway errors or origin server failures.

About

Build a caching server that caches responses from other servers.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages