EasyMultiCacheManager 1.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package EasyMultiCacheManager --version 1.2.0                
NuGet\Install-Package EasyMultiCacheManager -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="EasyMultiCacheManager" Version="1.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EasyMultiCacheManager --version 1.2.0                
#r "nuget: EasyMultiCacheManager, 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 EasyMultiCacheManager as a Cake Addin
#addin nuget:?package=EasyMultiCacheManager&version=1.2.0

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

Manage Cache Easily

Usage

First install package:

https://www.nuget.org/packages/EasyMultiCacheManager

If you want Redis then install:

https://www.nuget.org/packages/EasyMultiCacheManager.Redis

If you want Database then install:

https://www.nuget.org/packages/EasyMultiCacheManager.Database

then you can use like this:

var easyCacheManager = new CacheBuilder()
            .AddApi(new ApiConfig
            {
                Url = StaticData.Api
            })
            .AddRedis(new RedisConfig
            {
                ConnectionString = redisConnectionString
            })
            .AddDb(new DbConfig
            {
                ConnectionString = sqlConnectionString,
                Query = StaticData.QueryToSelect
            })
            .AddMemory(new MemoryConfig())
            .Build(new LockConfig());

var result = await easyCacheManager.GetAsync<string>("My-Key");

You can create your own provider with these interfaces:

  • IBaseCacheSource
  • ICacheSourceWithClear
  • ICacheSourceWithSet
  • ICacheSourceWithSetAndClear

Default providers are these:

  • MemoryCacheSource : ICacheSourceWithSetAndClear : Priority ⇒ 1
  • RedisCacheSource : ICacheSourceWithSetAndClear : Priority ⇒ 2
  • DbCacheSource : IBaseCacheSource : Priority ⇒ 3
  • ApiCacheSource : IBaseCacheSource : Priority ⇒ 4

On IBaseCacheSource you have only Get from cache, for example on ApiCacheSource you get real data from api.
if item find from one provider and not exist on other provider, it will automatically set to other providers that implemented from ICacheSourceWithSetAndClear or ICacheSourceWithSet

Example

First try get from Memory because it Priority is 1, if not exist it try get from redis, after that it try to get from db, and after that it get data from api. if not found it will return null.
also if found on db or api it will set to redis and memory.

Concurrency

This package use AsyncKeyedLock to handle lock on get, set and clear on specific key. so you use this package on multi thread program.

Info

You can use all type like class, object, string to cache, for example EasyCacheManager, EasyCacheManager<MyClass>
Priority should be unique, you can't crate EasyCacheManager with list of providers with same Priority

Clear cache

With ClearCacheAsync method you can clear specific key on all providers that implement ICacheSourceWithClear or ICacheSourceWithSetAndClear

Set

With SetAsync you can manually set value to provides that that implement ICacheSourceWithSet or ICacheSourceWithSetAndClear

Contributors

The following contributors have made this project better:

See the full list of contributors

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 is compatible.  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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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 (5)

Showing the top 5 NuGet packages that depend on EasyMultiCacheManager:

Package Downloads
EasyMultiCacheManager.Redis

Easy Cache Manager Redis

EasyMultiCacheManager.Database

Easy Cache Manager Database

EasyMultiCacheManager.Api

Easy Cache Manager Api

EasyMultiCacheManager.Clear

Easy Cache Manager Clear

EasyMultiCacheManager.SqlServer

Easy Cache Manager SqlServer Database

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.0 292 12/1/2024
2.0.0 157 11/27/2024
1.2.0 133 11/27/2024
1.1.0 73 11/25/2024
1.0.4 81 11/16/2024
1.0.3 90 11/13/2024
1.0.2 105 11/12/2024
1.0.1 110 11/11/2024
1.0.0 104 11/11/2024

CacheManager