Skip to content

Latest commit

Β 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Hybrid Cache Management System for Distributed Web Platforms

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

πŸ“š Overview

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.

Key Features

  • 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

Performance Benefits (from research)

  • 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

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         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  β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Cache Level Selection Logic

The adaptive algorithm automatically determines the optimal cache level based on:

  1. Access Frequency Score: How often data is accessed
  2. Recency Score: When data was last accessed (exponential decay)
  3. Data Size: Larger data stored in lower levels
  4. 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

πŸš€ Quick Start

Prerequisites

  • Java 17 or higher
  • Maven 3.9+
  • Docker & Docker Compose
  • Redis (optional - Docker Compose will start it)
  • Memcached (optional - Docker Compose will start it)

Running with Docker (Recommended)

  1. Clone the repository:
git clone https://github.com/yourusername/hybrid-cache-system.git
cd hybrid-cache-system
  1. Build and start all services:
docker-compose up --build

This will start:

  • Redis (port 6379)
  • Memcached (port 11211)
  • Demo Application (port 8080)
  1. Access the demo application:
http://localhost:8080

Running Locally

  1. Start Redis and Memcached (if not using Docker):
# Redis
redis-server

# Memcached
memcached -p 11211 -m 256
  1. Build the project:
mvn clean install
  1. Run the demo application:
cd hybrid-cache-demo
mvn spring-boot:run

πŸ“– Usage

As a Spring Boot Starter

  1. 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>
  1. 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
  1. 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;
    }
}

πŸ§ͺ Performance Testing

The demo application includes comprehensive performance tests comparing standard and hybrid caching.

Running Performance Tests

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%"
  }
}

Available Endpoints

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

πŸ“Š Monitoring

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

Key Metrics

  • 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

πŸ”§ Configuration Options

Local Cache Configuration

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 algorithm

Redis Configuration

hybrid:
  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 mode

Adaptive Algorithm Configuration

hybrid:
  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 prediction

🧬 Adaptive LRU-K Algorithm

The system implements an enhanced LRU-K algorithm that makes intelligent decisions about cache retention:

Traditional LRU

  • Evicts least recently used item
  • Only considers last access time
  • Simple but suboptimal

LRU-K (This Implementation)

  • Tracks K most recent access times
  • Evicts based on K-th most recent access
  • Better handles access patterns
  • Adapts to frequency + recency

Formula

LRU-K Score = current_time - time_of_kth_recent_access

Lower score = Keep in cache
Higher score = Candidate for eviction

🐳 Docker Configuration

The project includes a complete Docker setup:

Services

  • redis: Redis cache server (Alpine, 512MB max memory)
  • memcached: Memcached server (256MB)
  • demo-app: Spring Boot demo application

Commands

# 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 --build

πŸ“ˆ Research Results

Based 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%

πŸ›οΈ Project Structure

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

πŸ”¬ Research Background

This project is based on the diploma work:

Title: "Consistency Management Model in Hybrid Caches for Distributed Web Platforms"

Key Contributions:

  1. Multi-level hybrid caching architecture
  2. Adaptive LRU-K cache management algorithm
  3. Automatic cache level selection mechanism
  4. Performance optimization for distributed systems

Academic Supervisor: Dovzhenko Tymur Pavlovych, PhD, Associate Professor

Institution: State University of Information and Communication Technologies

πŸ“ License

This project is developed as part of academic research at the State University of Information and Communication Technologies.

πŸ‘¨β€πŸ’» Author

Ivan Striukov Student, Group PDM-53 Specialty: 121 Software Engineering State University of Information and Communication Technologies Email: i.striukov@gmail.com

πŸ™ Acknowledgments

  • Academic supervisor: Dovzhenko Tymur Pavlovych
  • State University of Information and Communication Technologies
  • Open source cache implementations (Caffeine, Jedis, XMemcached)

πŸ“š References

  1. Redis Documentation. URL: https://redis.io/documentation
  2. Memcached Documentation. URL: https://memcached.org/
  3. Wu X., et al. "Hybrid cache architecture with disparate memory technologies". ACM SIGARCH, 2009.
  4. 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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages