Skip to content

A high-performance distributed caching system built with .NET 9 and Redis, featuring cache invalidation, multiple caching strategies (Cache-Aside, Write-Through), and Clean Architecture. This project demonstrates how to optimize application speed and scalability using caching.

Notifications You must be signed in to change notification settings

MrEshboboyev/distributed-caching-system-with-cache-invalidation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Distributed Caching System with Cache Invalidation

.NET 9 Redis High Performance Caching Clean Architecture

A high-performance distributed caching system built with .NET 9 and Redis, featuring cache invalidation, multiple caching strategies (Cache-Aside, Write-Through), and Clean Architecture. This project demonstrates how to optimize application speed and scalability using caching.


πŸ”₯ Key Features

βœ… Distributed Caching – Uses Redis for low-latency, high-speed caching.
βœ… Cache Invalidation – Ensures data consistency with real-time updates.
βœ… Multiple Caching Strategies:

  • Cache-Aside (Lazy Loading) – Loads data only when needed.
  • Write-Through – Ensures cache and database consistency.
    βœ… Event-Driven Design – Uses Redis Pub/Sub for efficient cache invalidation.
    βœ… Scalable & High-Performance – Optimized for cloud & microservices.
    βœ… Clean Architecture – Ensures maintainability and modularity.

πŸ› οΈ Technologies Used

πŸ”Ή .NET 9 – Latest .NET version for cutting-edge performance.
πŸ”Ή Redis – Distributed caching system for low-latency storage.
πŸ”Ή StackExchange.Redis – .NET Redis client for caching.
πŸ”Ή Entity Framework Core – Database interactions & caching logic.
πŸ”Ή CQRS + MediatR – Implements query-command separation.
πŸ”Ή Serilog – Centralized logging for monitoring & observability.
πŸ”Ή Docker – Containerized Redis for easy setup.


πŸ›οΈ Architecture

This project follows Clean Architecture with domain-driven principles:

πŸ“Œ Domain Layer – Business logic, entities, and caching policies.
πŸ“Œ Application Layer – Queries, commands, and caching strategies.
πŸ“Œ Infrastructure Layer – Redis integration & repository patterns.
πŸ“Œ Presentation Layer – API controllers for cache interactions.


πŸ”„ How It Works

1️⃣ Cache-Aside (Lazy Loading)

πŸ”Ή Fetch from cache β†’ If miss, load from DB β†’ Store in cache β†’ Return response.

2️⃣ Write-Through

πŸ”Ή Write to cache & DB simultaneously β†’ Ensures strong consistency.

3️⃣ Cache Invalidation

πŸ”Ή Uses Redis Pub/Sub to remove outdated cache when data updates.


πŸš€ Getting Started

πŸ“Œ Prerequisites

βœ… .NET 9 SDK
βœ… Redis (for distributed caching)
βœ… Docker (for running Redis container)

Step 1: Clone the Repository

git clone https://github.com/MrEshboboyev/distributed-caching-system-with-cache-invalidation.git
cd distributed-caching-system-with-cache-invalidation

Step 2: Install Dependencies

dotnet restore

Step 3: Run Redis (Docker)

docker run -d -p 6379:6379 redis

Step 4: Run the Application

dotnet run --project src/App

πŸ”§ Configuration

Customize Redis settings in appsettings.json:

{
  "RedisSettings": {
    "ConnectionString": "localhost:6379",
    "InvalidationChannel": "cache-invalidation"
  },
  "CacheSettings": {
    "DefaultExpirationMinutes": 60
  }
}

🌐 API Endpoints

Method Endpoint Description
POST /api/products Create a product (Write-Through)
GET /api/products/{id} Fetch a product (Cache-Aside)
DELETE /api/products/{id} Delete a product (Invalidates Cache)

πŸ§ͺ Testing

Unit Tests

Run tests to ensure system stability:

dotnet test

Manual API Testing

πŸ“Œ Use Postman or any REST client to:
βœ… Create a product β†’ /api/products
βœ… Fetch the product β†’ /api/products/{id} (data should be cached)
βœ… Delete the product β†’ /api/products/{id} (cache invalidated)


🎯 Why Use This Project?

βœ… Lightning Fast Responses – Eliminates unnecessary DB queries.
βœ… Scalable & Fault-Tolerant – Designed for high-load applications.
βœ… Cache Consistency – Implements cache invalidation strategies.
βœ… Ready for Production – Follows best practices in caching.


πŸ“œ License

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


πŸ“ž Contact

For feedback, contributions, or questions:
πŸ“§ Email: mreshboboyev@gmail.com πŸ’» GitHub: MrEshboboyev


πŸš€ Supercharge your .NET apps with blazing-fast caching! Clone the repo & start optimizing today!

About

A high-performance distributed caching system built with .NET 9 and Redis, featuring cache invalidation, multiple caching strategies (Cache-Aside, Write-Through), and Clean Architecture. This project demonstrates how to optimize application speed and scalability using caching.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages