Skip to content

jaykeraliya0/caching-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Caching Proxy

A high-performance HTTP caching proxy server built in Go that forwards requests to an origin server and caches responses using Redis. When the same request is made again, it returns the cached response instead of forwarding to the origin server, significantly improving response times and reducing server load.

Features

  • HTTP Proxy: Forwards HTTP requests to any origin server
  • Redis Caching: Uses Redis for fast, persistent caching of responses
  • Cache Headers: Adds X-Cache: HIT or X-Cache: MISS headers to indicate cache status
  • Full Request Support: Preserves headers, query parameters, and request methods

Installation

git clone https://github.com/jaykeraliya0/caching-proxy.git
cd caching-proxy
go mod tidy
go build -o caching-proxy

Or install directly:

go install github.com/jaykeraliya0/caching-proxy@latest

Configuration

Set the Redis connection URL via environment variable:

REDIS_URL=localhost:6379

For Redis with authentication:

REDIS_URL=username:password@redis-server:6379

Usage

Start the Caching Proxy

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

Parameters:

  • --port, -p: Port on which the caching proxy server will run (required)
  • --origin, -o: URL of the origin server to forward requests to (required)

Clear Cache

./caching-proxy clear-cache

Examples

Basic Usage

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

# First request - Cache MISS (forwarded to origin)
curl http://localhost:3000/posts/1

# Second request - Cache HIT (served from cache)
curl http://localhost:3000/posts/1

Testing Cache Behavior

./caching-proxy start --port 3000 --origin https://httpbin.org

# Make a request (will be cached)
curl -v http://localhost:3000/get?test=123

# Check the X-Cache header in the response:
# First request: X-Cache: MISS
# Subsequent requests: X-Cache: HIT

Source

https://roadmap.sh/projects/caching-server


⭐ If you found this project helpful, please give it a star on GitHub!

About

A high-performance HTTP caching proxy server built in Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Contributors

Languages