Skip to content

Commit

Permalink
Add new caching providers
Browse files Browse the repository at this point in the history
  • Loading branch information
VahidN committed Jan 6, 2025
1 parent a54d181 commit c742262
Show file tree
Hide file tree
Showing 69 changed files with 3,131 additions and 779 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ jobs:
- name: Run EFCoreSecondLevelCacheInterceptor lib unit tests
run: dotnet test ./src/Tests/EFCoreSecondLevelCacheInterceptor.UnitTests/EFCoreSecondLevelCacheInterceptor.UnitTests.csproj --logger "console;verbosity=detailed"

- name: Build EFCoreSecondLevelCacheInterceptor.CacheManager.Core lib
run: dotnet build ./src/EFCoreSecondLevelCacheInterceptor.CacheManager.Core/EFCoreSecondLevelCacheInterceptor.CacheManager.Core.csproj --configuration Release

- name: Build EFCoreSecondLevelCacheInterceptor.EasyCaching.Core lib
run: dotnet build ./src/EFCoreSecondLevelCacheInterceptor.EasyCaching.Core/EFCoreSecondLevelCacheInterceptor.EasyCaching.Core.csproj --configuration Release

- name: Build EFCoreSecondLevelCacheInterceptor.MemoryCache lib
run: dotnet build ./src/EFCoreSecondLevelCacheInterceptor.MemoryCache/EFCoreSecondLevelCacheInterceptor.MemoryCache.csproj --configuration Release

- name: Build EFCoreSecondLevelCacheInterceptor.FusionCache lib
run: dotnet build ./src/EFCoreSecondLevelCacheInterceptor.FusionCache/EFCoreSecondLevelCacheInterceptor.FusionCache.csproj --configuration Release

- name: Build EFCoreSecondLevelCacheInterceptor.StackExchange.Redis lib
run: dotnet build ./src/EFCoreSecondLevelCacheInterceptor.StackExchange.Redis/EFCoreSecondLevelCacheInterceptor.StackExchange.Redis.csproj --configuration Release

- name: Push Package to NuGet.org
if: github.event_name == 'push'
run: dotnet nuget push **\*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate
90 changes: 90 additions & 0 deletions EFCoreSecondLevelCacheInterceptor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Issue192", "src\Tests\Issue
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCoreSecondLevelCacheInterceptor.UnitTests", "src\Tests\EFCoreSecondLevelCacheInterceptor.UnitTests\EFCoreSecondLevelCacheInterceptor.UnitTests.csproj", "{F77DD140-4762-426E-8FE0-3AD34DE3867A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCoreSecondLevelCacheInterceptor.CacheManager.Core", "src\EFCoreSecondLevelCacheInterceptor.CacheManager.Core\EFCoreSecondLevelCacheInterceptor.CacheManager.Core.csproj", "{C6EB0761-6A95-4B19-9E6C-C3814D116937}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCoreSecondLevelCacheInterceptor.EasyCaching.Core", "src\EFCoreSecondLevelCacheInterceptor.EasyCaching.Core\EFCoreSecondLevelCacheInterceptor.EasyCaching.Core.csproj", "{0654DC71-AC65-4428-A4E6-A4CE469EA959}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCoreSecondLevelCacheInterceptor.MemoryCache", "src\EFCoreSecondLevelCacheInterceptor.MemoryCache\EFCoreSecondLevelCacheInterceptor.MemoryCache.csproj", "{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCoreSecondLevelCacheInterceptor.HybridCache", "src\EFCoreSecondLevelCacheInterceptor.HybridCache\EFCoreSecondLevelCacheInterceptor.HybridCache.csproj", "{863CE238-6FB4-4910-851D-6F115E39728A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCoreSecondLevelCacheInterceptor.FusionCache", "src\EFCoreSecondLevelCacheInterceptor.FusionCache\EFCoreSecondLevelCacheInterceptor.FusionCache.csproj", "{61463B61-8487-441D-AA68-1B738516C88C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCoreSecondLevelCacheInterceptor.StackExchange.Redis", "src\EFCoreSecondLevelCacheInterceptor.StackExchange.Redis\EFCoreSecondLevelCacheInterceptor.StackExchange.Redis.csproj", "{70393506-60D8-412F-B053-B3CE8287F047}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -260,6 +272,78 @@ Global
{F77DD140-4762-426E-8FE0-3AD34DE3867A}.Release|x64.Build.0 = Release|Any CPU
{F77DD140-4762-426E-8FE0-3AD34DE3867A}.Release|x86.ActiveCfg = Release|Any CPU
{F77DD140-4762-426E-8FE0-3AD34DE3867A}.Release|x86.Build.0 = Release|Any CPU
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Debug|x64.ActiveCfg = Debug|Any CPU
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Debug|x64.Build.0 = Debug|Any CPU
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Debug|x86.ActiveCfg = Debug|Any CPU
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Debug|x86.Build.0 = Debug|Any CPU
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Release|Any CPU.Build.0 = Release|Any CPU
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Release|x64.ActiveCfg = Release|Any CPU
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Release|x64.Build.0 = Release|Any CPU
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Release|x86.ActiveCfg = Release|Any CPU
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Release|x86.Build.0 = Release|Any CPU
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Debug|x64.ActiveCfg = Debug|Any CPU
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Debug|x64.Build.0 = Debug|Any CPU
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Debug|x86.ActiveCfg = Debug|Any CPU
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Debug|x86.Build.0 = Debug|Any CPU
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Release|Any CPU.Build.0 = Release|Any CPU
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Release|x64.ActiveCfg = Release|Any CPU
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Release|x64.Build.0 = Release|Any CPU
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Release|x86.ActiveCfg = Release|Any CPU
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Release|x86.Build.0 = Release|Any CPU
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Debug|x64.ActiveCfg = Debug|Any CPU
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Debug|x64.Build.0 = Debug|Any CPU
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Debug|x86.ActiveCfg = Debug|Any CPU
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Debug|x86.Build.0 = Debug|Any CPU
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Release|Any CPU.Build.0 = Release|Any CPU
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Release|x64.ActiveCfg = Release|Any CPU
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Release|x64.Build.0 = Release|Any CPU
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Release|x86.ActiveCfg = Release|Any CPU
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Release|x86.Build.0 = Release|Any CPU
{863CE238-6FB4-4910-851D-6F115E39728A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{863CE238-6FB4-4910-851D-6F115E39728A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{863CE238-6FB4-4910-851D-6F115E39728A}.Debug|x64.ActiveCfg = Debug|Any CPU
{863CE238-6FB4-4910-851D-6F115E39728A}.Debug|x64.Build.0 = Debug|Any CPU
{863CE238-6FB4-4910-851D-6F115E39728A}.Debug|x86.ActiveCfg = Debug|Any CPU
{863CE238-6FB4-4910-851D-6F115E39728A}.Debug|x86.Build.0 = Debug|Any CPU
{863CE238-6FB4-4910-851D-6F115E39728A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{863CE238-6FB4-4910-851D-6F115E39728A}.Release|Any CPU.Build.0 = Release|Any CPU
{863CE238-6FB4-4910-851D-6F115E39728A}.Release|x64.ActiveCfg = Release|Any CPU
{863CE238-6FB4-4910-851D-6F115E39728A}.Release|x64.Build.0 = Release|Any CPU
{863CE238-6FB4-4910-851D-6F115E39728A}.Release|x86.ActiveCfg = Release|Any CPU
{863CE238-6FB4-4910-851D-6F115E39728A}.Release|x86.Build.0 = Release|Any CPU
{61463B61-8487-441D-AA68-1B738516C88C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{61463B61-8487-441D-AA68-1B738516C88C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61463B61-8487-441D-AA68-1B738516C88C}.Debug|x64.ActiveCfg = Debug|Any CPU
{61463B61-8487-441D-AA68-1B738516C88C}.Debug|x64.Build.0 = Debug|Any CPU
{61463B61-8487-441D-AA68-1B738516C88C}.Debug|x86.ActiveCfg = Debug|Any CPU
{61463B61-8487-441D-AA68-1B738516C88C}.Debug|x86.Build.0 = Debug|Any CPU
{61463B61-8487-441D-AA68-1B738516C88C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61463B61-8487-441D-AA68-1B738516C88C}.Release|Any CPU.Build.0 = Release|Any CPU
{61463B61-8487-441D-AA68-1B738516C88C}.Release|x64.ActiveCfg = Release|Any CPU
{61463B61-8487-441D-AA68-1B738516C88C}.Release|x64.Build.0 = Release|Any CPU
{61463B61-8487-441D-AA68-1B738516C88C}.Release|x86.ActiveCfg = Release|Any CPU
{61463B61-8487-441D-AA68-1B738516C88C}.Release|x86.Build.0 = Release|Any CPU
{70393506-60D8-412F-B053-B3CE8287F047}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{70393506-60D8-412F-B053-B3CE8287F047}.Debug|Any CPU.Build.0 = Debug|Any CPU
{70393506-60D8-412F-B053-B3CE8287F047}.Debug|x64.ActiveCfg = Debug|Any CPU
{70393506-60D8-412F-B053-B3CE8287F047}.Debug|x64.Build.0 = Debug|Any CPU
{70393506-60D8-412F-B053-B3CE8287F047}.Debug|x86.ActiveCfg = Debug|Any CPU
{70393506-60D8-412F-B053-B3CE8287F047}.Debug|x86.Build.0 = Debug|Any CPU
{70393506-60D8-412F-B053-B3CE8287F047}.Release|Any CPU.ActiveCfg = Release|Any CPU
{70393506-60D8-412F-B053-B3CE8287F047}.Release|Any CPU.Build.0 = Release|Any CPU
{70393506-60D8-412F-B053-B3CE8287F047}.Release|x64.ActiveCfg = Release|Any CPU
{70393506-60D8-412F-B053-B3CE8287F047}.Release|x64.Build.0 = Release|Any CPU
{70393506-60D8-412F-B053-B3CE8287F047}.Release|x86.ActiveCfg = Release|Any CPU
{70393506-60D8-412F-B053-B3CE8287F047}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{EB8ADB13-3CE7-4A85-A70C-229972476023} = {CDC8E8F6-5261-4CF2-846E-F8C438438663}
Expand All @@ -281,5 +365,11 @@ Global
{93359BAE-B026-4680-9818-D06EE408B910} = {4E1F72D1-5A8F-4569-A57A-42E706B6A318}
{72079056-6752-43FD-BA53-E0BF5EFFF2C2} = {4E1F72D1-5A8F-4569-A57A-42E706B6A318}
{F77DD140-4762-426E-8FE0-3AD34DE3867A} = {C250B77E-090A-4FBE-BB73-2D91774A6929}
{C6EB0761-6A95-4B19-9E6C-C3814D116937} = {CDC8E8F6-5261-4CF2-846E-F8C438438663}
{0654DC71-AC65-4428-A4E6-A4CE469EA959} = {CDC8E8F6-5261-4CF2-846E-F8C438438663}
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB} = {CDC8E8F6-5261-4CF2-846E-F8C438438663}
{863CE238-6FB4-4910-851D-6F115E39728A} = {CDC8E8F6-5261-4CF2-846E-F8C438438663}
{61463B61-8487-441D-AA68-1B738516C88C} = {CDC8E8F6-5261-4CF2-846E-F8C438438663}
{70393506-60D8-412F-B053-B3CE8287F047} = {CDC8E8F6-5261-4CF2-846E-F8C438438663}
EndGlobalSection
EndGlobal
115 changes: 111 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,127 @@
# EF Core 3.1.x, 5x, 6x, 7x & 8x Second Level Cache Interceptor
# EF Core Second Level Cache Interceptor

[![EFCoreSecondLevelCacheInterceptor](https://github.com/VahidN/EFCoreSecondLevelCacheInterceptor/workflows/.NET%20Core%20Build/badge.svg)](https://github.com/VahidN/EFCoreSecondLevelCacheInterceptor)

Second level caching is a query cache. The results of EF commands will be stored in the cache, so that the same EF commands will retrieve their data from the cache rather than executing them against the database again.

## Install via NuGet

To install EFCoreSecondLevelCacheInterceptor, run the following command in the Package Manager Console:
## How to upgrade to version 5

To support more advanced caching providers, this library uses different assemblies and NuGet packages now.
To upgrade to version 5, first remove the `EFCoreSecondLevelCacheInterceptor` dependency. It doesn't have any built-in caching provider anymore.
But you can still use it to introduce your own custom caching provider by calling its `options.UseCustomCacheProvider<T>()` method (and you won't need the new packages).
To install `EFCoreSecondLevelCacheInterceptor` as before, run the following command in the Package Manager Console:

[![Nuget](https://img.shields.io/nuget/v/EFCoreSecondLevelCacheInterceptor)](http://www.nuget.org/packages/EFCoreSecondLevelCacheInterceptor/)

```powershell
PM> Install-Package EFCoreSecondLevelCacheInterceptor
```

You can also view the [package page](http://www.nuget.org/packages/EFCoreSecondLevelCacheInterceptor/) on NuGet.
But if you were using the built-in `In-Memory` cache provider, just install this new package:

[![Nuget](https://img.shields.io/nuget/v/EFCoreSecondLevelCacheInterceptor.MemoryCache)](http://www.nuget.org/packages/EFCoreSecondLevelCacheInterceptor.MemoryCache/)
```powershell
PM> Install-Package EFCoreSecondLevelCacheInterceptor.MemoryCache
```

Or if you were using the `EasyCaching.Core provider`, install the new `EFCoreSecondLevelCacheInterceptor.EasyCaching.Core` package:

[![Nuget](https://img.shields.io/nuget/v/EFCoreSecondLevelCacheInterceptor.EasyCaching.Core)](http://www.nuget.org/packages/EFCoreSecondLevelCacheInterceptor.EasyCaching.Core/)
```powershell
PM> Install-Package EFCoreSecondLevelCacheInterceptor.EasyCaching.Core
```

Or if you were using the `CacheManager.Core provider`, install the new `EFCoreSecondLevelCacheInterceptor.CacheManager.Core` package:

[![Nuget](https://img.shields.io/nuget/v/EFCoreSecondLevelCacheInterceptor.CacheManager.Core)](http://www.nuget.org/packages/EFCoreSecondLevelCacheInterceptor.CacheManager.Core/)
```powershell
PM> Install-Package EFCoreSecondLevelCacheInterceptor.CacheManager.Core
```

Also there are two new caching providers available in V5:

### 1- EFCoreSecondLevelCacheInterceptor.StackExchange.Redis

This provider uses the StackExchange.Redis as a cache provider and it's preconfigured with a MessagePack serializer. To use it, first you should install its new NuGet package:

[![Nuget](https://img.shields.io/nuget/v/EFCoreSecondLevelCacheInterceptor.StackExchange.Redis)](http://www.nuget.org/packages/EFCoreSecondLevelCacheInterceptor.StackExchange.Redis/)
```powershell
PM> Install-Package EFCoreSecondLevelCacheInterceptor.StackExchange.Redis
```

And then you need to register its required services:

```csharp
var redisOptions = new ConfigurationOptions
{
EndPoints = new EndPointCollection
{
{
"127.0.0.1", 6379
}
},
AllowAdmin = true,
ConnectTimeout = 10000
};

services.AddEFSecondLevelCache(options
=> options.UseStackExchangeRedisCacheProvider(redisOptions, TimeSpan.FromMinutes(minutes: 5)));
```

### 2- EFCoreSecondLevelCacheInterceptor.FusionCache

This provider uses the [FusionCache](https://github.com/ZiggyCreatures/FusionCache) as a cache provider. To use it, first you should install its new NuGet package:

[![Nuget](https://img.shields.io/nuget/v/EFCoreSecondLevelCacheInterceptor.FusionCache)](http://www.nuget.org/packages/EFCoreSecondLevelCacheInterceptor.FusionCache/)
```powershell
PM> Install-Package EFCoreSecondLevelCacheInterceptor.FusionCache
```

And then this is how you can register its required services:

```csharp
services.AddFusionCache()
.WithOptions(options =>
{
options.DefaultEntryOptions = new FusionCacheEntryOptions
{
// CACHE DURATION
Duration = TimeSpan.FromMinutes(minutes: 1),

// FAIL-SAFE OPTIONS
IsFailSafeEnabled = true,
FailSafeMaxDuration = TimeSpan.FromHours(hours: 2),
FailSafeThrottleDuration = TimeSpan.FromSeconds(seconds: 30),

// FACTORY TIMEOUTS
FactorySoftTimeout = TimeSpan.FromMilliseconds(milliseconds: 500),
FactoryHardTimeout = TimeSpan.FromMilliseconds(milliseconds: 1500),

// DISTRIBUTED CACHE
DistributedCacheSoftTimeout = TimeSpan.FromSeconds(seconds: 10),
DistributedCacheHardTimeout = TimeSpan.FromSeconds(seconds: 20),
AllowBackgroundDistributedCacheOperations = true,

// JITTERING
JitterMaxDuration = TimeSpan.FromSeconds(seconds: 2)
};

// DISTIBUTED CACHE CIRCUIT-BREAKER
options.DistributedCacheCircuitBreakerDuration = TimeSpan.FromSeconds(seconds: 2);

// CUSTOM LOG LEVELS
options.FailSafeActivationLogLevel = LogLevel.Debug;
options.SerializationErrorsLogLevel = LogLevel.Warning;
options.DistributedCacheSyntheticTimeoutsLogLevel = LogLevel.Debug;
options.DistributedCacheErrorsLogLevel = LogLevel.Error;
options.FactorySyntheticTimeoutsLogLevel = LogLevel.Debug;
options.FactoryErrorsLogLevel = LogLevel.Error;
});

services.AddEFSecondLevelCache(options => options.UseFusionCacheProvider());
```


## Usage ([1](#1--register-a-preferred-cache-provider) & [2](#2--add-secondlevelcacheinterceptor-to-your-dbcontextoptionsbuilder-pipeline) are mandatory)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class EFCacheManagerCoreProvider : IEFCacheServiceProvider
private readonly ICacheManager<EFCachedData> _valuesCacheManager;

/// <summary>
/// Using IMemoryCache as a cache service.
/// Using CacheManagerCore as a cache service.
/// </summary>
public EFCacheManagerCoreProvider(ICacheManager<ISet<string>> dependenciesCacheManager,
ICacheManager<EFCachedData> valuesCacheManager,
Expand Down Expand Up @@ -46,7 +46,7 @@ public EFCacheManagerCoreProvider(ICacheManager<ISet<string>> dependenciesCacheM
/// <param name="cacheKey">key</param>
/// <param name="value">value</param>
/// <param name="cachePolicy">Defines the expiration mode of the cache item.</param>
public void InsertValue(EFCacheKey cacheKey, EFCachedData value, EFCachePolicy cachePolicy)
public void InsertValue(EFCacheKey cacheKey, EFCachedData? value, EFCachePolicy cachePolicy)
{
if (cacheKey is null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;

namespace EFCoreSecondLevelCacheInterceptor;

/// <summary>
/// Defines EFCoreSecondLevel's Options
/// </summary>
public static class EFCacheManagerCoreProviderOptions
{
/// <summary>
/// Introduces the built-in `CacheManagerCoreProvider` to be used as the CacheProvider.
/// </summary>
public static EFCoreSecondLevelCacheOptions UseCacheManagerCoreProvider(this EFCoreSecondLevelCacheOptions options)
{
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}

options.Settings.CacheProvider = typeof(EFCacheManagerCoreProvider);

return options;
}

/// <summary>
/// Introduces the built-in `CacheManagerCoreProvider` to be used as the CacheProvider.
/// If you specify the `Cacheable()` method options, its setting will override this global setting.
/// </summary>
/// <param name="options"></param>
/// <param name="expirationMode">Defines the expiration mode of the cache items globally.</param>
/// <param name="timeout">The expiration timeout.</param>
public static EFCoreSecondLevelCacheOptions UseCacheManagerCoreProvider(this EFCoreSecondLevelCacheOptions options,
CacheExpirationMode expirationMode,
TimeSpan timeout)
{
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}

options.Settings.CacheProvider = typeof(EFCacheManagerCoreProvider);

options.Settings.CachableQueriesOptions = new CachableQueriesOptions
{
ExpirationMode = expirationMode,
Timeout = timeout,
IsActive = true
};

return options;
}
}
Loading

0 comments on commit c742262

Please sign in to comment.