A lightweight HTTP proxy server implemented in Java that provides caching capabilities using an LRU (Least Recently Used) caching strategy.
- HTTP proxy server with response caching
- LRU (Least Recently Used) cache implementation
- Configurable cache capacity (default: 3 entries)
- Custom port configuration
- Origin server URL configuration
- Cache clearing functionality
- Cache hit/miss tracking via response headers
- Java 17 or higher
- Maven 3.8+
- Windows/Linux/macOS
mvn clean packageRun the proxy server using the following command:
java -jar target/caching-proxy-1.0-SNAPSHOT.jar --port <port> --origin <origin-url>| Argument | Description | Required | Default |
|---|---|---|---|
--port |
Port number for the proxy server | No | 4000 |
--origin |
Origin server URL (must start with http:// or https://) | Yes | - |
--clear-cache |
Clear the cache and exit | No | false |
Start the proxy server on port 3000:
java -jar target/caching-proxy-1.0-SNAPSHOT.jar --port 3000 --origin https://api.example.comClear the cache:
java -jar target/caching-proxy-1.0-SNAPSHOT.jar --clear-cache- The proxy server accepts incoming HTTP requests
- For each request, it:
- Checks if the response is in the cache
- If found (HIT): Returns cached response with
X-Cache: HITheader - If not found (MISS):
- Forwards request to origin server
- Caches the response
- Returns response with
X-Cache: MISSheader
- Uses LRU eviction policy when cache reaches capacity
src/main/java/org/muchiri/
├── Main.java # Entry point and argument handling
├── Server.java # Proxy server implementation
├── ProxyHandler.java # Request/response handler
├── Cache.java # Cache interface
├── LRUCache.java # LRU cache implementation
└── ArgType.java # Command line argument types
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request