A Spring Boot-based HTTP caching proxy server that caches responses from an upstream server using Redis.
- 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-Cacheheader (HIT/MISS) to indicate cache status
- Java 21
- Maven
- Redis (via Docker Compose)
Set the following environment variables:
PROXY_UPSTREAM_SERVER_HOST- The upstream server URL to proxyREDIS_HOST- Redis server hostnameREDIS_PORT- Redis server portCACHE_DURATION_SECONDS- Cache TTL in seconds
-
Start Redis:
docker-compose up -d
-
Set environment variables:
export PROXY_UPSTREAM_SERVER_HOST=http://example.com export REDIS_HOST=localhost export REDIS_PORT=6379 export CACHE_DURATION_SECONDS=300
-
Run the application:
./mvnw spring-boot:run
GET /**- Proxy any GET request to the upstream server with cachingPOST /clear- Clear all cached responses
- Client sends GET request to the proxy
- Proxy checks Redis cache for the URL
- On cache miss: fetches from upstream server, stores in Redis, returns response
- On cache hit: returns cached response directly
- All responses include
X-Cache: HITorX-Cache: MISSheader
- Spring Boot 3.5.9
- Spring Data Redis
- Java 21
- Redis 7.4.1