Skip to content

imaad666/Distributed-Cache-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Distributed Cache System

This project implements a distributed in-memory cache system using Java and Spring Boot. It features an LRU eviction policy, thread-safe operations, a simple REST API for cache operations, and basic clustering support with consistent hashing.

Key Features

  • LRU Eviction Policy: Automatically removes the least recently used entries when the cache reaches its limit.
  • Thread-Safe Operations: Utilizes ConcurrentHashMap to ensure safe access to cache entries in a multi-threaded environment.
  • REST API: Provides endpoints for creating, retrieving, and deleting cache entries.
  • Clustering Support: Implements consistent hashing to distribute cache entries across multiple nodes.

Technologies Used

  • Java
  • Spring Boot
  • ConcurrentHashMap
  • REST API

Project Structure

distributed-cache-system
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ main
β”‚   β”‚   β”œβ”€β”€ java
β”‚   β”‚   β”‚   └── com
β”‚   β”‚   β”‚       └── example
β”‚   β”‚   β”‚           β”œβ”€β”€ cache
β”‚   β”‚   β”‚           β”‚   β”œβ”€β”€ CacheApplication.java
β”‚   β”‚   β”‚           β”‚   β”œβ”€β”€ controller
β”‚   β”‚   β”‚           β”‚   β”‚   └── CacheController.java
β”‚   β”‚   β”‚           β”‚   β”œβ”€β”€ service
β”‚   β”‚   β”‚           β”‚   β”‚   └── CacheService.java
β”‚   β”‚   β”‚           β”‚   β”œβ”€β”€ model
β”‚   β”‚   β”‚           β”‚   β”‚   └── CacheEntry.java
β”‚   β”‚   β”‚           β”‚   └── clustering
β”‚   β”‚   β”‚           β”‚       └── ConsistentHashing.java
β”‚   β”‚   β”œβ”€β”€ resources
β”‚   β”‚   β”‚   β”œβ”€β”€ application.properties
β”‚   β”‚   β”‚   └── static
β”‚   β”‚   β”‚       └── dashboard.html
β”‚   β”œβ”€β”€ test
β”‚   β”‚   └── java
β”‚   β”‚       └── com
β”‚   β”‚           └── example
β”‚   β”‚               └── cache
β”‚   β”‚                   └── CacheServiceTest.java
β”œβ”€β”€ pom.xml
└── README.md

Setup Instructions

  1. Clone the repository:

    git clone https://github.com/yourusername/distributed-cache-system.git
    cd distributed-cache-system
    
  2. Build the project using Maven:

    mvn clean install
    
  3. Run the application:

    mvn spring-boot:run
    
  4. Access the REST API at http://localhost:8080/api/cache.

API Documentation

  • Create Cache Entry

    • Endpoint: POST /api/cache
    • Request Body: { "key": "string", "value": "string" }
    • Response: 201 Created
  • Get Cache Entry

    • Endpoint: GET /api/cache/{key}
    • Response: 200 OK with cache entry details or 404 Not Found
  • Delete Cache Entry

    • Endpoint: DELETE /api/cache/{key}
    • Response: 204 No Content

Unit Tests

Unit tests for the CacheService class are located in src/test/java/com/example/cache/CacheServiceTest.java. Run the tests using:

mvn test

Dashboard

A simple HTML dashboard is provided to monitor cache statistics. Access it at http://localhost:8080/dashboard.html.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

⚑ Distributed In-Memory Cache System built with Java 17 and Spring Boot. Features a thread-safe LRU cache, RESTful API access, basic clustering support with consistent hashing, and a simple HTML dashboard to monitor cache stats. πŸš€

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages