Skip to content

Commit c742262

Browse files
committed
Add new caching providers
1 parent a54d181 commit c742262

File tree

69 files changed

+3131
-779
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+3131
-779
lines changed

.github/workflows/build.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ jobs:
1919
- name: Run EFCoreSecondLevelCacheInterceptor lib unit tests
2020
run: dotnet test ./src/Tests/EFCoreSecondLevelCacheInterceptor.UnitTests/EFCoreSecondLevelCacheInterceptor.UnitTests.csproj --logger "console;verbosity=detailed"
2121

22+
- name: Build EFCoreSecondLevelCacheInterceptor.CacheManager.Core lib
23+
run: dotnet build ./src/EFCoreSecondLevelCacheInterceptor.CacheManager.Core/EFCoreSecondLevelCacheInterceptor.CacheManager.Core.csproj --configuration Release
24+
25+
- name: Build EFCoreSecondLevelCacheInterceptor.EasyCaching.Core lib
26+
run: dotnet build ./src/EFCoreSecondLevelCacheInterceptor.EasyCaching.Core/EFCoreSecondLevelCacheInterceptor.EasyCaching.Core.csproj --configuration Release
27+
28+
- name: Build EFCoreSecondLevelCacheInterceptor.MemoryCache lib
29+
run: dotnet build ./src/EFCoreSecondLevelCacheInterceptor.MemoryCache/EFCoreSecondLevelCacheInterceptor.MemoryCache.csproj --configuration Release
30+
31+
- name: Build EFCoreSecondLevelCacheInterceptor.FusionCache lib
32+
run: dotnet build ./src/EFCoreSecondLevelCacheInterceptor.FusionCache/EFCoreSecondLevelCacheInterceptor.FusionCache.csproj --configuration Release
33+
34+
- name: Build EFCoreSecondLevelCacheInterceptor.StackExchange.Redis lib
35+
run: dotnet build ./src/EFCoreSecondLevelCacheInterceptor.StackExchange.Redis/EFCoreSecondLevelCacheInterceptor.StackExchange.Redis.csproj --configuration Release
36+
2237
- name: Push Package to NuGet.org
2338
if: github.event_name == 'push'
2439
run: dotnet nuget push **\*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate

EFCoreSecondLevelCacheInterceptor.sln

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Issue192", "src\Tests\Issue
4343
EndProject
4444
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCoreSecondLevelCacheInterceptor.UnitTests", "src\Tests\EFCoreSecondLevelCacheInterceptor.UnitTests\EFCoreSecondLevelCacheInterceptor.UnitTests.csproj", "{F77DD140-4762-426E-8FE0-3AD34DE3867A}"
4545
EndProject
46+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCoreSecondLevelCacheInterceptor.CacheManager.Core", "src\EFCoreSecondLevelCacheInterceptor.CacheManager.Core\EFCoreSecondLevelCacheInterceptor.CacheManager.Core.csproj", "{C6EB0761-6A95-4B19-9E6C-C3814D116937}"
47+
EndProject
48+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCoreSecondLevelCacheInterceptor.EasyCaching.Core", "src\EFCoreSecondLevelCacheInterceptor.EasyCaching.Core\EFCoreSecondLevelCacheInterceptor.EasyCaching.Core.csproj", "{0654DC71-AC65-4428-A4E6-A4CE469EA959}"
49+
EndProject
50+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCoreSecondLevelCacheInterceptor.MemoryCache", "src\EFCoreSecondLevelCacheInterceptor.MemoryCache\EFCoreSecondLevelCacheInterceptor.MemoryCache.csproj", "{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}"
51+
EndProject
52+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCoreSecondLevelCacheInterceptor.HybridCache", "src\EFCoreSecondLevelCacheInterceptor.HybridCache\EFCoreSecondLevelCacheInterceptor.HybridCache.csproj", "{863CE238-6FB4-4910-851D-6F115E39728A}"
53+
EndProject
54+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCoreSecondLevelCacheInterceptor.FusionCache", "src\EFCoreSecondLevelCacheInterceptor.FusionCache\EFCoreSecondLevelCacheInterceptor.FusionCache.csproj", "{61463B61-8487-441D-AA68-1B738516C88C}"
55+
EndProject
56+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCoreSecondLevelCacheInterceptor.StackExchange.Redis", "src\EFCoreSecondLevelCacheInterceptor.StackExchange.Redis\EFCoreSecondLevelCacheInterceptor.StackExchange.Redis.csproj", "{70393506-60D8-412F-B053-B3CE8287F047}"
57+
EndProject
4658
Global
4759
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4860
Debug|Any CPU = Debug|Any CPU
@@ -260,6 +272,78 @@ Global
260272
{F77DD140-4762-426E-8FE0-3AD34DE3867A}.Release|x64.Build.0 = Release|Any CPU
261273
{F77DD140-4762-426E-8FE0-3AD34DE3867A}.Release|x86.ActiveCfg = Release|Any CPU
262274
{F77DD140-4762-426E-8FE0-3AD34DE3867A}.Release|x86.Build.0 = Release|Any CPU
275+
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
276+
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Debug|Any CPU.Build.0 = Debug|Any CPU
277+
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Debug|x64.ActiveCfg = Debug|Any CPU
278+
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Debug|x64.Build.0 = Debug|Any CPU
279+
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Debug|x86.ActiveCfg = Debug|Any CPU
280+
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Debug|x86.Build.0 = Debug|Any CPU
281+
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Release|Any CPU.ActiveCfg = Release|Any CPU
282+
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Release|Any CPU.Build.0 = Release|Any CPU
283+
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Release|x64.ActiveCfg = Release|Any CPU
284+
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Release|x64.Build.0 = Release|Any CPU
285+
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Release|x86.ActiveCfg = Release|Any CPU
286+
{C6EB0761-6A95-4B19-9E6C-C3814D116937}.Release|x86.Build.0 = Release|Any CPU
287+
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
288+
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Debug|Any CPU.Build.0 = Debug|Any CPU
289+
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Debug|x64.ActiveCfg = Debug|Any CPU
290+
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Debug|x64.Build.0 = Debug|Any CPU
291+
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Debug|x86.ActiveCfg = Debug|Any CPU
292+
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Debug|x86.Build.0 = Debug|Any CPU
293+
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Release|Any CPU.ActiveCfg = Release|Any CPU
294+
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Release|Any CPU.Build.0 = Release|Any CPU
295+
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Release|x64.ActiveCfg = Release|Any CPU
296+
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Release|x64.Build.0 = Release|Any CPU
297+
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Release|x86.ActiveCfg = Release|Any CPU
298+
{0654DC71-AC65-4428-A4E6-A4CE469EA959}.Release|x86.Build.0 = Release|Any CPU
299+
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
300+
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
301+
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Debug|x64.ActiveCfg = Debug|Any CPU
302+
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Debug|x64.Build.0 = Debug|Any CPU
303+
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Debug|x86.ActiveCfg = Debug|Any CPU
304+
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Debug|x86.Build.0 = Debug|Any CPU
305+
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
306+
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Release|Any CPU.Build.0 = Release|Any CPU
307+
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Release|x64.ActiveCfg = Release|Any CPU
308+
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Release|x64.Build.0 = Release|Any CPU
309+
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Release|x86.ActiveCfg = Release|Any CPU
310+
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB}.Release|x86.Build.0 = Release|Any CPU
311+
{863CE238-6FB4-4910-851D-6F115E39728A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
312+
{863CE238-6FB4-4910-851D-6F115E39728A}.Debug|Any CPU.Build.0 = Debug|Any CPU
313+
{863CE238-6FB4-4910-851D-6F115E39728A}.Debug|x64.ActiveCfg = Debug|Any CPU
314+
{863CE238-6FB4-4910-851D-6F115E39728A}.Debug|x64.Build.0 = Debug|Any CPU
315+
{863CE238-6FB4-4910-851D-6F115E39728A}.Debug|x86.ActiveCfg = Debug|Any CPU
316+
{863CE238-6FB4-4910-851D-6F115E39728A}.Debug|x86.Build.0 = Debug|Any CPU
317+
{863CE238-6FB4-4910-851D-6F115E39728A}.Release|Any CPU.ActiveCfg = Release|Any CPU
318+
{863CE238-6FB4-4910-851D-6F115E39728A}.Release|Any CPU.Build.0 = Release|Any CPU
319+
{863CE238-6FB4-4910-851D-6F115E39728A}.Release|x64.ActiveCfg = Release|Any CPU
320+
{863CE238-6FB4-4910-851D-6F115E39728A}.Release|x64.Build.0 = Release|Any CPU
321+
{863CE238-6FB4-4910-851D-6F115E39728A}.Release|x86.ActiveCfg = Release|Any CPU
322+
{863CE238-6FB4-4910-851D-6F115E39728A}.Release|x86.Build.0 = Release|Any CPU
323+
{61463B61-8487-441D-AA68-1B738516C88C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
324+
{61463B61-8487-441D-AA68-1B738516C88C}.Debug|Any CPU.Build.0 = Debug|Any CPU
325+
{61463B61-8487-441D-AA68-1B738516C88C}.Debug|x64.ActiveCfg = Debug|Any CPU
326+
{61463B61-8487-441D-AA68-1B738516C88C}.Debug|x64.Build.0 = Debug|Any CPU
327+
{61463B61-8487-441D-AA68-1B738516C88C}.Debug|x86.ActiveCfg = Debug|Any CPU
328+
{61463B61-8487-441D-AA68-1B738516C88C}.Debug|x86.Build.0 = Debug|Any CPU
329+
{61463B61-8487-441D-AA68-1B738516C88C}.Release|Any CPU.ActiveCfg = Release|Any CPU
330+
{61463B61-8487-441D-AA68-1B738516C88C}.Release|Any CPU.Build.0 = Release|Any CPU
331+
{61463B61-8487-441D-AA68-1B738516C88C}.Release|x64.ActiveCfg = Release|Any CPU
332+
{61463B61-8487-441D-AA68-1B738516C88C}.Release|x64.Build.0 = Release|Any CPU
333+
{61463B61-8487-441D-AA68-1B738516C88C}.Release|x86.ActiveCfg = Release|Any CPU
334+
{61463B61-8487-441D-AA68-1B738516C88C}.Release|x86.Build.0 = Release|Any CPU
335+
{70393506-60D8-412F-B053-B3CE8287F047}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
336+
{70393506-60D8-412F-B053-B3CE8287F047}.Debug|Any CPU.Build.0 = Debug|Any CPU
337+
{70393506-60D8-412F-B053-B3CE8287F047}.Debug|x64.ActiveCfg = Debug|Any CPU
338+
{70393506-60D8-412F-B053-B3CE8287F047}.Debug|x64.Build.0 = Debug|Any CPU
339+
{70393506-60D8-412F-B053-B3CE8287F047}.Debug|x86.ActiveCfg = Debug|Any CPU
340+
{70393506-60D8-412F-B053-B3CE8287F047}.Debug|x86.Build.0 = Debug|Any CPU
341+
{70393506-60D8-412F-B053-B3CE8287F047}.Release|Any CPU.ActiveCfg = Release|Any CPU
342+
{70393506-60D8-412F-B053-B3CE8287F047}.Release|Any CPU.Build.0 = Release|Any CPU
343+
{70393506-60D8-412F-B053-B3CE8287F047}.Release|x64.ActiveCfg = Release|Any CPU
344+
{70393506-60D8-412F-B053-B3CE8287F047}.Release|x64.Build.0 = Release|Any CPU
345+
{70393506-60D8-412F-B053-B3CE8287F047}.Release|x86.ActiveCfg = Release|Any CPU
346+
{70393506-60D8-412F-B053-B3CE8287F047}.Release|x86.Build.0 = Release|Any CPU
263347
EndGlobalSection
264348
GlobalSection(NestedProjects) = preSolution
265349
{EB8ADB13-3CE7-4A85-A70C-229972476023} = {CDC8E8F6-5261-4CF2-846E-F8C438438663}
@@ -281,5 +365,11 @@ Global
281365
{93359BAE-B026-4680-9818-D06EE408B910} = {4E1F72D1-5A8F-4569-A57A-42E706B6A318}
282366
{72079056-6752-43FD-BA53-E0BF5EFFF2C2} = {4E1F72D1-5A8F-4569-A57A-42E706B6A318}
283367
{F77DD140-4762-426E-8FE0-3AD34DE3867A} = {C250B77E-090A-4FBE-BB73-2D91774A6929}
368+
{C6EB0761-6A95-4B19-9E6C-C3814D116937} = {CDC8E8F6-5261-4CF2-846E-F8C438438663}
369+
{0654DC71-AC65-4428-A4E6-A4CE469EA959} = {CDC8E8F6-5261-4CF2-846E-F8C438438663}
370+
{404FFBBC-49A7-4AC3-8FFF-84B21AA70EAB} = {CDC8E8F6-5261-4CF2-846E-F8C438438663}
371+
{863CE238-6FB4-4910-851D-6F115E39728A} = {CDC8E8F6-5261-4CF2-846E-F8C438438663}
372+
{61463B61-8487-441D-AA68-1B738516C88C} = {CDC8E8F6-5261-4CF2-846E-F8C438438663}
373+
{70393506-60D8-412F-B053-B3CE8287F047} = {CDC8E8F6-5261-4CF2-846E-F8C438438663}
284374
EndGlobalSection
285375
EndGlobal

README.md

Lines changed: 111 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,127 @@
1-
# EF Core 3.1.x, 5x, 6x, 7x & 8x Second Level Cache Interceptor
1+
# EF Core Second Level Cache Interceptor
22

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

55
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.
66

7-
## Install via NuGet
87

9-
To install EFCoreSecondLevelCacheInterceptor, run the following command in the Package Manager Console:
8+
## How to upgrade to version 5
9+
10+
To support more advanced caching providers, this library uses different assemblies and NuGet packages now.
11+
To upgrade to version 5, first remove the `EFCoreSecondLevelCacheInterceptor` dependency. It doesn't have any built-in caching provider anymore.
12+
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).
13+
To install `EFCoreSecondLevelCacheInterceptor` as before, run the following command in the Package Manager Console:
1014

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

1317
```powershell
1418
PM> Install-Package EFCoreSecondLevelCacheInterceptor
1519
```
1620

17-
You can also view the [package page](http://www.nuget.org/packages/EFCoreSecondLevelCacheInterceptor/) on NuGet.
21+
But if you were using the built-in `In-Memory` cache provider, just install this new package:
22+
23+
[![Nuget](https://img.shields.io/nuget/v/EFCoreSecondLevelCacheInterceptor.MemoryCache)](http://www.nuget.org/packages/EFCoreSecondLevelCacheInterceptor.MemoryCache/)
24+
```powershell
25+
PM> Install-Package EFCoreSecondLevelCacheInterceptor.MemoryCache
26+
```
27+
28+
Or if you were using the `EasyCaching.Core provider`, install the new `EFCoreSecondLevelCacheInterceptor.EasyCaching.Core` package:
29+
30+
[![Nuget](https://img.shields.io/nuget/v/EFCoreSecondLevelCacheInterceptor.EasyCaching.Core)](http://www.nuget.org/packages/EFCoreSecondLevelCacheInterceptor.EasyCaching.Core/)
31+
```powershell
32+
PM> Install-Package EFCoreSecondLevelCacheInterceptor.EasyCaching.Core
33+
```
34+
35+
Or if you were using the `CacheManager.Core provider`, install the new `EFCoreSecondLevelCacheInterceptor.CacheManager.Core` package:
36+
37+
[![Nuget](https://img.shields.io/nuget/v/EFCoreSecondLevelCacheInterceptor.CacheManager.Core)](http://www.nuget.org/packages/EFCoreSecondLevelCacheInterceptor.CacheManager.Core/)
38+
```powershell
39+
PM> Install-Package EFCoreSecondLevelCacheInterceptor.CacheManager.Core
40+
```
41+
42+
Also there are two new caching providers available in V5:
43+
44+
### 1- EFCoreSecondLevelCacheInterceptor.StackExchange.Redis
45+
46+
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:
47+
48+
[![Nuget](https://img.shields.io/nuget/v/EFCoreSecondLevelCacheInterceptor.StackExchange.Redis)](http://www.nuget.org/packages/EFCoreSecondLevelCacheInterceptor.StackExchange.Redis/)
49+
```powershell
50+
PM> Install-Package EFCoreSecondLevelCacheInterceptor.StackExchange.Redis
51+
```
52+
53+
And then you need to register its required services:
54+
55+
```csharp
56+
var redisOptions = new ConfigurationOptions
57+
{
58+
EndPoints = new EndPointCollection
59+
{
60+
{
61+
"127.0.0.1", 6379
62+
}
63+
},
64+
AllowAdmin = true,
65+
ConnectTimeout = 10000
66+
};
67+
68+
services.AddEFSecondLevelCache(options
69+
=> options.UseStackExchangeRedisCacheProvider(redisOptions, TimeSpan.FromMinutes(minutes: 5)));
70+
```
71+
72+
### 2- EFCoreSecondLevelCacheInterceptor.FusionCache
73+
74+
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:
75+
76+
[![Nuget](https://img.shields.io/nuget/v/EFCoreSecondLevelCacheInterceptor.FusionCache)](http://www.nuget.org/packages/EFCoreSecondLevelCacheInterceptor.FusionCache/)
77+
```powershell
78+
PM> Install-Package EFCoreSecondLevelCacheInterceptor.FusionCache
79+
```
80+
81+
And then this is how you can register its required services:
82+
83+
```csharp
84+
services.AddFusionCache()
85+
.WithOptions(options =>
86+
{
87+
options.DefaultEntryOptions = new FusionCacheEntryOptions
88+
{
89+
// CACHE DURATION
90+
Duration = TimeSpan.FromMinutes(minutes: 1),
91+
92+
// FAIL-SAFE OPTIONS
93+
IsFailSafeEnabled = true,
94+
FailSafeMaxDuration = TimeSpan.FromHours(hours: 2),
95+
FailSafeThrottleDuration = TimeSpan.FromSeconds(seconds: 30),
96+
97+
// FACTORY TIMEOUTS
98+
FactorySoftTimeout = TimeSpan.FromMilliseconds(milliseconds: 500),
99+
FactoryHardTimeout = TimeSpan.FromMilliseconds(milliseconds: 1500),
100+
101+
// DISTRIBUTED CACHE
102+
DistributedCacheSoftTimeout = TimeSpan.FromSeconds(seconds: 10),
103+
DistributedCacheHardTimeout = TimeSpan.FromSeconds(seconds: 20),
104+
AllowBackgroundDistributedCacheOperations = true,
105+
106+
// JITTERING
107+
JitterMaxDuration = TimeSpan.FromSeconds(seconds: 2)
108+
};
109+
110+
// DISTIBUTED CACHE CIRCUIT-BREAKER
111+
options.DistributedCacheCircuitBreakerDuration = TimeSpan.FromSeconds(seconds: 2);
112+
113+
// CUSTOM LOG LEVELS
114+
options.FailSafeActivationLogLevel = LogLevel.Debug;
115+
options.SerializationErrorsLogLevel = LogLevel.Warning;
116+
options.DistributedCacheSyntheticTimeoutsLogLevel = LogLevel.Debug;
117+
options.DistributedCacheErrorsLogLevel = LogLevel.Error;
118+
options.FactorySyntheticTimeoutsLogLevel = LogLevel.Debug;
119+
options.FactoryErrorsLogLevel = LogLevel.Error;
120+
});
121+
122+
services.AddEFSecondLevelCache(options => options.UseFusionCacheProvider());
123+
```
124+
18125

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

src/EFCoreSecondLevelCacheInterceptor/EFCacheManagerCoreProvider.cs renamed to src/EFCoreSecondLevelCacheInterceptor.CacheManager.Core/EFCacheManagerCoreProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class EFCacheManagerCoreProvider : IEFCacheServiceProvider
1717
private readonly ICacheManager<EFCachedData> _valuesCacheManager;
1818

1919
/// <summary>
20-
/// Using IMemoryCache as a cache service.
20+
/// Using CacheManagerCore as a cache service.
2121
/// </summary>
2222
public EFCacheManagerCoreProvider(ICacheManager<ISet<string>> dependenciesCacheManager,
2323
ICacheManager<EFCachedData> valuesCacheManager,
@@ -46,7 +46,7 @@ public EFCacheManagerCoreProvider(ICacheManager<ISet<string>> dependenciesCacheM
4646
/// <param name="cacheKey">key</param>
4747
/// <param name="value">value</param>
4848
/// <param name="cachePolicy">Defines the expiration mode of the cache item.</param>
49-
public void InsertValue(EFCacheKey cacheKey, EFCachedData value, EFCachePolicy cachePolicy)
49+
public void InsertValue(EFCacheKey cacheKey, EFCachedData? value, EFCachePolicy cachePolicy)
5050
{
5151
if (cacheKey is null)
5252
{
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
3+
namespace EFCoreSecondLevelCacheInterceptor;
4+
5+
/// <summary>
6+
/// Defines EFCoreSecondLevel's Options
7+
/// </summary>
8+
public static class EFCacheManagerCoreProviderOptions
9+
{
10+
/// <summary>
11+
/// Introduces the built-in `CacheManagerCoreProvider` to be used as the CacheProvider.
12+
/// </summary>
13+
public static EFCoreSecondLevelCacheOptions UseCacheManagerCoreProvider(this EFCoreSecondLevelCacheOptions options)
14+
{
15+
if (options == null)
16+
{
17+
throw new ArgumentNullException(nameof(options));
18+
}
19+
20+
options.Settings.CacheProvider = typeof(EFCacheManagerCoreProvider);
21+
22+
return options;
23+
}
24+
25+
/// <summary>
26+
/// Introduces the built-in `CacheManagerCoreProvider` to be used as the CacheProvider.
27+
/// If you specify the `Cacheable()` method options, its setting will override this global setting.
28+
/// </summary>
29+
/// <param name="options"></param>
30+
/// <param name="expirationMode">Defines the expiration mode of the cache items globally.</param>
31+
/// <param name="timeout">The expiration timeout.</param>
32+
public static EFCoreSecondLevelCacheOptions UseCacheManagerCoreProvider(this EFCoreSecondLevelCacheOptions options,
33+
CacheExpirationMode expirationMode,
34+
TimeSpan timeout)
35+
{
36+
if (options == null)
37+
{
38+
throw new ArgumentNullException(nameof(options));
39+
}
40+
41+
options.Settings.CacheProvider = typeof(EFCacheManagerCoreProvider);
42+
43+
options.Settings.CachableQueriesOptions = new CachableQueriesOptions
44+
{
45+
ExpirationMode = expirationMode,
46+
Timeout = timeout,
47+
IsActive = true
48+
};
49+
50+
return options;
51+
}
52+
}

0 commit comments

Comments
 (0)