Skip to content

Abhineshhh/caching-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Caching Proxy

A Spring Boot-based HTTP caching proxy server that caches responses from an upstream server using Redis.

Features

  • HTTP Proxy: Forwards GET requests to a configurable upstream server
  • Redis Caching: Caches responses with configurable TTL to reduce upstream load
  • Cache Management: Clear cache endpoint for manual cache invalidation
  • Cache Headers: Responses include X-Cache header (HIT/MISS) to indicate cache status

Prerequisites

  • Java 21
  • Maven
  • Redis (via Docker Compose)

Configuration

Set the following environment variables:

  • PROXY_UPSTREAM_SERVER_HOST - The upstream server URL to proxy
  • REDIS_HOST - Redis server hostname
  • REDIS_PORT - Redis server port
  • CACHE_DURATION_SECONDS - Cache TTL in seconds

Quick Start

  1. Start Redis:

    docker-compose up -d
  2. Set environment variables:

    export PROXY_UPSTREAM_SERVER_HOST=http://example.com
    export REDIS_HOST=localhost
    export REDIS_PORT=6379
    export CACHE_DURATION_SECONDS=300
  3. Run the application:

    ./mvnw spring-boot:run

API Endpoints

  • GET /** - Proxy any GET request to the upstream server with caching
  • POST /clear - Clear all cached responses

How It Works

  1. Client sends GET request to the proxy
  2. Proxy checks Redis cache for the URL
  3. On cache miss: fetches from upstream server, stores in Redis, returns response
  4. On cache hit: returns cached response directly
  5. All responses include X-Cache: HIT or X-Cache: MISS header

Technology Stack

  • Spring Boot 3.5.9
  • Spring Data Redis
  • Java 21
  • Redis 7.4.1

About

A caching server that caches responses from other servers.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages