A Spring Boot-based cache proxy service that forwards requests to backend APIs and caches responses to improve performance.
- ✅ REST API proxy with automatic caching
- ✅ In-memory caching with Spring Cache abstraction
- ✅ Cache hit/miss tracking and statistics
- ✅ Admin endpoints for cache management
- ✅ Configurable TTL (Time To Live)
- ✅ Docker support
- Java 17
- Spring Boot 3.4.12
- Spring Cache (In-memory)
- Maven
- Docker
smart-cache-proxy/
├── src/
│ ├── main/
│ │ ├── java/com/shubh/cacheproxy/
│ │ │ ├── SmartCacheProxyApplication.java
│ │ │ ├── controller/
│ │ │ │ ├── HealthController.java
│ │ │ │ ├── ProxyController.java
│ │ │ │ └── CacheAdminController.java
│ │ │ ├── service/
│ │ │ │ ├── ProxyService.java
│ │ │ │ └── CacheStatsService.java
│ │ │ └── model/
│ │ │ └── ProxyResponse.java
│ │ └── resources/
│ │ └── application.yaml
├── Dockerfile
├── docker-compose.yml
└── pom.xml
- Java 17 or higher
- Maven 3.6+
- Docker (optional)
- Clone the repository
git clone <your-repo-url>
cd smart-cache-proxy- Build the project
./mvnw clean install- Run the application
./mvnw spring-boot:runThe application will start on http://localhost:8080
- Build the JAR file
./mvnw clean package- Build and run with Docker Compose
docker-compose up --buildGET /api/healthReturns the health status of the service.
GET /api/pingSimple ping endpoint.
GET /proxy?path=<target-path>Forwards the request to the backend API and caches the response.
Example:
curl "http://localhost:8080/proxy?path=/posts/1"Response:
{
"statusCode": 200,
"body": "{ ... }",
"responseTime": 703,
"fromCache": false
}GET /cache/statsResponse:
{
"totalRequests": 5,
"cacheHits": 3,
"cacheMisses": 2,
"hitRate": "60.00%"
}DELETE /cache/clearResponse:
{
"message": "Cache cleared successfully"
}Configuration is managed in src/main/resources/application.yaml:
spring:
application:
name: smartCacheProxy
cache:
type: simple
cache-names: api-cache
server:
port: 8080
proxy:
backend:
base-url: https://jsonplaceholder.typicode.com- Client sends a request to
/proxy?path=/posts/1 - ProxyController checks if the response is in cache
- If CACHE HIT: Returns cached response (fast)
- If CACHE MISS: Forwards request to backend API, caches the response, then returns it
- Subsequent requests to the same path are served from cache
- Spring Boot: REST API development
- Dependency Injection: Service layer architecture
- Spring Cache:
@Cacheableannotation for caching - Response Wrapping: Custom response model with metadata
- Statistics Tracking: Thread-safe atomic counters
- Docker: Containerization
- First Request: ~700ms (fetches from backend)
- Cached Request: <10ms (served from cache)
- Improvement: ~99% faster response time
- Redis integration for distributed caching
- Multiple cache eviction strategies (LRU, LFU)
- Cache warming on startup
- Request rate limiting
- Response compression
Shubh
- Blockchain Developer
- Backend Engineer
This project is open source and available under the MIT License.