A Spring Boot starter implementing a multi-level hybrid caching architecture with adaptive consistency management for distributed web platforms.
Diploma Project | State University of Information and Communication Technologies
This project implements a sophisticated hybrid caching system that combines multiple caching technologies (Local Cache, Redis, Memcached, CDN) into a unified, intelligent caching solution. The system uses an adaptive LRU-K algorithm to automatically optimize cache utilization and data distribution across different cache levels.
- Multi-Level Architecture: 4-tier caching system (Local β Redis β Memcached β CDN)
- Adaptive LRU-K Algorithm: Intelligent eviction policy that tracks K recent accesses
- Automatic Level Selection: Data automatically stored at optimal cache level based on access patterns
- Cache Promotion: Frequently accessed data automatically promoted to faster levels
- Comprehensive Metrics: Detailed performance statistics for each cache level
- Spring Boot Integration: Easy integration via auto-configuration
- Docker Support: Ready-to-run Docker Compose setup
- 40-60% reduction in response time
- 70-80% reduction in database load
- 6x increase in system throughput
- 89% cache hit rate with 78% memory utilization
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Users β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Level 4: CDN β
β (Static Resources Distribution) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Level 1: Local Cache β
β (Caffeine + Adaptive LRU-K Algorithm) β
β β’ Fastest access (sub-millisecond) β
β β’ Per-server scope β
β β’ Adaptive eviction policy β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Level 2: Redis Cache β
β (Distributed Shared Cache) β
β β’ Fast access (~1ms) β
β β’ Cross-server data sharing β
β β’ Persistence support β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Level 3: Memcached β
β (SQL Query Results) β
β β’ Optimized for simple key-value β
β β’ High throughput β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββ
β Origin Database β
ββββββββββββββββββββ
The adaptive algorithm automatically determines the optimal cache level based on:
- Access Frequency Score: How often data is accessed
- Recency Score: When data was last accessed (exponential decay)
- Data Size: Larger data stored in lower levels
- LRU-K Score: Backward K-distance calculation
Score = FrequencyScore Γ RecencyScore
if score > 10.0 β LOCAL cache
if score > 2.0 β REDIS cache
if size < 1MB β MEMCACHED
else β CDN
- Java 17 or higher
- Maven 3.9+
- Docker & Docker Compose
- Redis (optional - Docker Compose will start it)
- Memcached (optional - Docker Compose will start it)
- Clone the repository:
git clone https://github.com/yourusername/hybrid-cache-system.git
cd hybrid-cache-system- Build and start all services:
docker-compose up --buildThis will start:
- Redis (port 6379)
- Memcached (port 11211)
- Demo Application (port 8080)
- Access the demo application:
http://localhost:8080
- Start Redis and Memcached (if not using Docker):
# Redis
redis-server
# Memcached
memcached -p 11211 -m 256- Build the project:
mvn clean install- Run the demo application:
cd hybrid-cache-demo
mvn spring-boot:run- Add dependency to your
pom.xml:
<dependency>
<groupId>com.istriukov.diploma</groupId>
<artifactId>hybrid-cache-spring-boot-starter</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>- Configure in
application.yml:
hybrid:
cache:
enabled: true
local:
enabled: true
max-size: 10000
expire-after-write: 10m
lru-k-value: 2
redis:
enabled: true
host: localhost
port: 6379
default-ttl: 1h
adaptive:
enabled: true
predictive-caching: true- Use in your code:
@Service
public class YourService {
@Autowired
private HybridCacheManager<String, MyData> cacheManager;
public MyData getData(String id) {
// Try to get from cache
Optional<MyData> cached = cacheManager.get(id);
if (cached.isPresent()) {
return cached.get();
}
// Fetch from database
MyData data = database.findById(id);
// Store in cache (automatic level selection)
cacheManager.put(id, data);
return data;
}
}The demo application includes comprehensive performance tests comparing standard and hybrid caching.
Via REST API:
curl -X POST "http://localhost:8080/api/cache/test/performance?iterations=1000&uniqueKeys=100"Response Example:
{
"testConfiguration": {
"iterations": 1000,
"uniqueKeys": 100
},
"standardCaching": {
"avgOperationTimeMs": "48.5",
"hitRate": "82.3%",
"throughput": "412 ops/sec"
},
"hybridCaching": {
"avgOperationTimeMs": "24.2",
"hitRate": "89.1%",
"throughput": "825 ops/sec"
},
"improvement": {
"responseTimeImprovement": "50.1%",
"throughputImprovement": "100.2%",
"hitRateImprovement": "6.8%"
}
}| Endpoint | Method | Description |
|---|---|---|
/api/cache/data/{id} |
GET | Retrieve cached data |
/api/cache/data/{id} |
POST | Store data in cache |
/api/cache/data/{id} |
DELETE | Evict data from cache |
/api/cache/statistics |
GET | Get cache statistics |
/api/cache/test/performance |
POST | Run performance test |
/api/cache/summary |
GET | Get performance summary |
/api/cache/clear |
DELETE | Clear all caches |
The system provides comprehensive metrics through Spring Boot Actuator:
# Health check
curl http://localhost:8080/actuator/health
# Metrics
curl http://localhost:8080/actuator/metrics
# Cache statistics
curl http://localhost:8080/api/cache/statistics- Hit Rate: Percentage of requests served from cache
- Miss Rate: Percentage of requests requiring database access
- Average Response Time: Mean time per operation
- Throughput: Operations per second
- Cache Size: Number of entries per level
- Eviction Count: Number of entries evicted
hybrid:
cache:
local:
enabled: true # Enable/disable local cache
max-size: 10000 # Maximum number of entries
expire-after-write: 10m # Expiration after write
expire-after-access: 5m # Expiration after last access
initial-capacity: 100 # Initial cache capacity
lru-k-value: 2 # K parameter for LRU-K algorithmhybrid:
cache:
redis:
enabled: true # Enable/disable Redis cache
host: localhost # Redis server host
port: 6379 # Redis server port
password: # Redis password (optional)
database: 0 # Redis database number
timeout: 2s # Connection timeout
max-connections: 50 # Max connection pool size
default-ttl: 1h # Default TTL for entries
cluster-mode: false # Enable Redis cluster modehybrid:
cache:
adaptive:
enabled: true # Enable adaptive algorithm
monitoring-interval: 1m # Metrics collection interval
hit-rate-threshold: 0.75 # Rebalancing trigger threshold
predictive-caching: true # Enable predictive caching
correlation-threshold: 0.6 # Correlation threshold for predictionThe system implements an enhanced LRU-K algorithm that makes intelligent decisions about cache retention:
- Evicts least recently used item
- Only considers last access time
- Simple but suboptimal
- Tracks K most recent access times
- Evicts based on K-th most recent access
- Better handles access patterns
- Adapts to frequency + recency
LRU-K Score = current_time - time_of_kth_recent_access
Lower score = Keep in cache
Higher score = Candidate for eviction
The project includes a complete Docker setup:
- redis: Redis cache server (Alpine, 512MB max memory)
- memcached: Memcached server (256MB)
- demo-app: Spring Boot demo application
# Start all services
docker-compose up
# Start in background
docker-compose up -d
# Stop all services
docker-compose down
# View logs
docker-compose logs -f demo-app
# Rebuild and start
docker-compose up --buildBased on experimental evaluation with 10,000 concurrent users and 5,000 requests/second:
| Metric | No Cache | Standard Cache | Hybrid Cache | Improvement |
|---|---|---|---|---|
| Response Time | 245ms | 52ms | 24ms | 50% |
| Database Load | 100% | 40% | 22% | 78% |
| Throughput | 800 ops/s | 3,840 ops/s | 4,800 ops/s | 600% |
| Hit Rate | 0% | 85% | 89% | 4% |
hybrid-cache-system/
βββ hybrid-cache-spring-boot-starter/ # Main starter module
β βββ src/main/java/
β β βββ com/istriukov/diploma/cache/
β β βββ config/ # Configuration classes
β β βββ core/ # Core interfaces
β β βββ impl/ # Cache implementations
β β βββ autoconfigure/ # Spring Boot auto-config
β βββ pom.xml
β
βββ hybrid-cache-demo/ # Demo application
β βββ src/main/java/
β β βββ com/istriukov/diploma/demo/
β β βββ controller/ # REST controllers
β β βββ service/ # Business services
β βββ src/main/resources/
β β βββ application.yml # Configuration
β βββ Dockerfile
β βββ pom.xml
β
βββ docker-compose.yml # Docker orchestration
βββ pom.xml # Parent POM
βββ README.md # This file
This project is based on the diploma work:
Title: "Consistency Management Model in Hybrid Caches for Distributed Web Platforms"
Key Contributions:
- Multi-level hybrid caching architecture
- Adaptive LRU-K cache management algorithm
- Automatic cache level selection mechanism
- Performance optimization for distributed systems
Academic Supervisor: Dovzhenko Tymur Pavlovych, PhD, Associate Professor
Institution: State University of Information and Communication Technologies
This project is developed as part of academic research at the State University of Information and Communication Technologies.
Ivan Striukov Student, Group PDM-53 Specialty: 121 Software Engineering State University of Information and Communication Technologies Email: i.striukov@gmail.com
- Academic supervisor: Dovzhenko Tymur Pavlovych
- State University of Information and Communication Technologies
- Open source cache implementations (Caffeine, Jedis, XMemcached)
- Redis Documentation. URL: https://redis.io/documentation
- Memcached Documentation. URL: https://memcached.org/
- Wu X., et al. "Hybrid cache architecture with disparate memory technologies". ACM SIGARCH, 2009.
- Caffeine Cache. URL: https://github.com/ben-manes/caffeine
For presentation and demonstration purposes, this system showcases the practical implementation of hybrid caching research concepts.