DualCache.NET 1.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DualCache.NET --version 1.2.0                
NuGet\Install-Package DualCache.NET -Version 1.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DualCache.NET" Version="1.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DualCache.NET --version 1.2.0                
#r "nuget: DualCache.NET, 1.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DualCache.NET as a Cake Addin
#addin nuget:?package=DualCache.NET&version=1.2.0

// Install DualCache.NET as a Cake Tool
#tool nuget:?package=DualCache.NET&version=1.2.0                

DualCache.NET

DualCache.NET Logo

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.

Build Status

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 need to set it up in your Startup.cs or Program.cs file and in your appsettings.json, add the RedisConnection. Here's how you can do it:

{
  "ConnectionStrings": {
    "RedisConnection": "your_redis_connection_string"
  }
}
builder.Services.AddRedisCache(Configuration);

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.2 206 10/18/2024
1.2.0 128 10/18/2024
1.1.2 130 10/18/2024
1.0.1 129 10/18/2024