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.
β
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.
πΉ .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.
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.
πΉ Fetch from cache β If miss, load from DB β Store in cache β Return response.
πΉ Write to cache & DB simultaneously β Ensures strong consistency.
πΉ Uses Redis Pub/Sub to remove outdated cache when data updates.
β
.NET 9 SDK
β
Redis (for distributed caching)
β
Docker (for running Redis container)
git clone https://github.com/MrEshboboyev/distributed-caching-system-with-cache-invalidation.git
cd distributed-caching-system-with-cache-invalidation
dotnet restore
docker run -d -p 6379:6379 redis
dotnet run --project src/App
Customize Redis settings in appsettings.json
:
{
"RedisSettings": {
"ConnectionString": "localhost:6379",
"InvalidationChannel": "cache-invalidation"
},
"CacheSettings": {
"DefaultExpirationMinutes": 60
}
}
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) |
Run tests to ensure system stability:
dotnet test
π 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)
β
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.
This project is licensed under the MIT License. See LICENSE for details.
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!