A Spring Boot HTTP caching proxy server that sits between clients and origin servers to improve response times and reduce load.
- HTTP Proxy: Forward requests to origin server with transparent caching
- Smart Cache Keys: Based on HTTP method, URL, headers, and request body
- Header Filtering: Excludes non-essential headers (host, accept-encoding) to improve cache hit rates
- Cache Management: Clear cache via REST endpoint or CLI
- Cache Status: Responses include
X-Cache: HIT/MISSheader - Dual Mode: Web server or CLI-only cache clearing
java -jar cache-server.jar --port=8080 --origin.url=https://api.example.comjava -jar cache-server.jar --clear-cache --target.port=8080DELETE http://localhost:8080/clear| Parameter | Description | Example |
|---|---|---|
--port |
Cache server port | --port=8080 |
--origin.url |
Origin server URL | --origin.url=https://api.example.com |
--target.port |
Target port for CLI cache clear | --target.port=8080 |
--clear-cache |
Enable CLI cache clearing mode | --clear-cache |
- Cache Key: Generated from HTTP method + URL + filtered headers + request body
- Cache Hit: Returns cached response with
X-Cache: HITheader - Cache Miss: Fetches from origin, caches response, returns with
X-Cache: MISSheader - Filtered Headers:
hostandaccept-encodingare excluded from cache keys
* /**
All HTTP methods are supported and forwarded to the configured origin server.
DELETE /clear
Clears all cached responses.
- Java 17+
- Spring Boot 3.x
- ProxyController: Handles incoming HTTP requests
- ProxyService: Core caching logic and origin communication
- CacheKey: Smart cache key generation
- CacheClearCli: CLI-based cache management
- ResponseWrapper: Serializable response container
- Start cache server proxying to JSONPlaceholder:
java -jar cache-server.jar --port=3000 --origin.url=https://jsonplaceholder.typicode.com- Make requests through cache:
curl http://localhost:3000/posts/1
# X-Cache: MISS (first request)
curl http://localhost:3000/posts/1
# X-Cache: HIT (cached response)- Clear cache:
curl -X DELETE http://localhost:3000/clear