DualCache.NET
1.2.2
dotnet add package DualCache.NET --version 1.2.2
NuGet\Install-Package DualCache.NET -Version 1.2.2
<PackageReference Include="DualCache.NET" Version="1.2.2" />
paket add DualCache.NET --version 1.2.2
#r "nuget: DualCache.NET, 1.2.2"
// Install DualCache.NET as a Cake Addin #addin nuget:?package=DualCache.NET&version=1.2.2 // Install DualCache.NET as a Cake Tool #tool nuget:?package=DualCache.NET&version=1.2.2
DualCache.NET
DualCache.NET is a versatile caching library for .NET that provides seamless integration with both Redis and in-memory caching solutions. Enhance your application’s performance by reducing database load and improving response times effortlessly.
Features
- Multi-Cache Support: Switch between Redis and in-memory caching based on your needs.
- Simple Interface: Easy-to-use methods for setting, retrieving, and removing cached items.
- GetOrAdd Functionality: Automatically retrieve or create cached items, minimizing boilerplate code.
- Configuration Flexibility: Easily configure caching options through dependency injection.
- Seamless Switching: You can switch from RedisCache to MemoryCache without any code changes!
Installation
You can install DualCache.NET via NuGet Package Manager:
Install-Package DualCache.NET
Configuration RedisCache
To configure the cache service in your .NET application, you can set it up in your Startup.cs
or Program.cs
file. You have two options for providing the Redis connection string: through the appsettings.json
file or directly as a string.
Here's how you can do it:
Option 1: Using appsettings.json
If you want to use an IConfiguration
instance, add the Redis connection string in your appsettings.json
like this:
{
"ConnectionStrings": {
"RedisConnection": "your_redis_connection_string"
}
}
builder.Services.AddRedisCache(Configuration);
Option 2: Using a String Connection
If you want to use an IConfiguration
instance, add the Redis connection string in your appsettings.json
like this:
builder.Services.AddRedisCache("your_redis_connection_string");
Configuration MemoryCache
To inject memory cache, simply call:
builder.Services.AddCustomMemoryCache();
Usage
Once the cache is configured, you can use it in your application as follows:
Example Service with Caching:
using DualCache.NET;
public class ExampleService
{
private readonly ICacheService _cacheService;
public ExampleService(ICacheService cacheService)
{
_cacheService = cacheService;
}
public async Task<string> GetCachedValue(string key)
{
return await _cacheService.GetAsync<string>(key);
}
public async Task SetCachedValue(string key, string value)
{
await _cacheService.SetAsync(key, value);
}
public async Task<string> GetOrAddAsync(string key)
{
return await _cacheService.GetOrAddAsync(
"key",
async () => await Task.FromResult<string>("value"));
}
public async Task RemoveCachedValue(string key)
{
await _cacheService.RemoveAsync(key);
}
public async Task<bool> KeyExist(string key)
{
return await _cacheService.ExistsAsync(key);
}
}
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. |
.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.Caching.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- StackExchange.Redis (>= 2.8.16)
- 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.