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: [email protected]
💻 GitHub: MrEshboboyev
🚀 Supercharge your .NET apps with blazing-fast caching! Clone the repo & start optimizing today!