BigInt.AzureRedisCache.MiddleWare
2.0.2
dotnet add package BigInt.AzureRedisCache.MiddleWare --version 2.0.2
NuGet\Install-Package BigInt.AzureRedisCache.MiddleWare -Version 2.0.2
<PackageReference Include="BigInt.AzureRedisCache.MiddleWare" Version="2.0.2" />
<PackageVersion Include="BigInt.AzureRedisCache.MiddleWare" Version="2.0.2" />
<PackageReference Include="BigInt.AzureRedisCache.MiddleWare" />
paket add BigInt.AzureRedisCache.MiddleWare --version 2.0.2
#r "nuget: BigInt.AzureRedisCache.MiddleWare, 2.0.2"
#:package BigInt.AzureRedisCache.MiddleWare@2.0.2
#addin nuget:?package=BigInt.AzureRedisCache.MiddleWare&version=2.0.2
#tool nuget:?package=BigInt.AzureRedisCache.MiddleWare&version=2.0.2
BigInt.AzureRedisCache.MiddleWare
A modern, high-performance, and resilient Azure Redis Cache library for .NET applications. This package simplifies Redis integration by providing a robust service-based API with full Dependency Injection support and automatic self-healing.
Key Features
- Production-Ready: Implements Microsoft's best practices for
ConnectionMultiplexermanagement. - Resilient: Automatic "Force Reconnect" logic for handling transient Azure Redis connection issues.
- Async-First: All operations are asynchronous to prevent thread-blocking.
- Clean API: Simple
IRedisCacheServicewithGetAsync<T>,SetAsync<T>, andRemoveAsync. - Modern Serialization: Uses
System.Text.Json(v8+) for high-performance object serialization. - DI Friendly: Easy registration via
AddAzureRedisCacheextension method. - Observable: Full integration with
ILoggerfor better diagnostic support.
Installation
dotnet add package BigInt.AzureRedisCache.MiddleWare
Usage by .NET Version
This package is optimized for all modern .NET versions, including .NET 6 (LTS), .NET 8 (LTS), and .NET 10 (Preview).
1. Registration (Program.cs / Minimal API)
All versions starting from .NET 6 use the same clean registration syntax in Program.cs.
using BigInt.AzureRedisCache.MiddleWare;
var builder = <Application>.CreateBuilder(args);
// Register the Azure Redis Cache Service
builder.Services.AddAzureRedisCache(options =>
{
options.ConnectionString = builder.Configuration.GetConnectionString("Redis");
options.InstanceName = "MyApp"; // Optional prefix for all keys
options.DefaultExpiry = TimeSpan.FromHours(24);
options.ThrowOnError = false; // Prevents app crashes if Redis is down
});
2. Inject and Use
.NET 8 & .NET 10 Style (Primary Constructors)
If you are using .NET 8 or 10, simplify your code using Primary Constructors.
public class MyService(IRedisCacheService cache)
{
public async Task ProcessDataAsync(string key)
{
// Simple Set
await cache.SetAsync(key, new { Id = 1, Status = "Active" });
// Simple Get
var data = await cache.GetAsync<dynamic>(key);
}
}
.NET 6 Style (Standard DI)
For .NET 6 or older C# versions, use the standard constructor injection.
public class MyService
{
private readonly IRedisCacheService _cache;
public MyService(IRedisCacheService cache)
{
_cache = cache;
}
public async Task DoWorkAsync()
{
await _cache.SetAsync("user:123", new { Name = "John" }, TimeSpan.FromHours(1));
var user = await _cache.GetAsync<dynamic>("user:123");
}
}
Minimal API Usage
app.MapGet("/cache/{id}", async (string id, IRedisCacheService cache) =>
{
return await cache.GetAsync<object>(id);
});
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
ConnectionString |
string |
null |
Required. Your Redis connection string. |
InstanceName |
string |
"" |
Optional prefix for all keys (e.g. Dev:, Prod:). |
DefaultExpiry |
TimeSpan |
24 Hours | Default cache duration for objects. |
ThrowOnError |
bool |
true |
Whether to propagate Redis exceptions or fail gracefully. |
Resilience and Fault Tolerance
This library handles connection pooling and self-healing. If Redis becomes temporarily unavailable or if a connection timeout occurs in Azure, the library will:
- Log the error via
ILogger. - Attempt automatic retries for transient failures.
- Automatically re-create the
ConnectionMultiplexerif errors persist (Force Reconnect pattern).
Developed by Marimuthu Kandasamy (BigInt Technical Systems)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.2)
- StackExchange.Redis (>= 2.7.33)
- System.Text.Json (>= 8.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Integrated Embedded Icon, SourceLink for debugging, and corrected symbols package alignment.