From d1e4ff48b1b368e255fa979c9d73595bb6a2defb Mon Sep 17 00:00:00 2001 From: Peter Morlion Date: Fri, 26 Jan 2024 08:35:51 +0100 Subject: [PATCH 1/3] Remove references to Redis where it doesn't apply --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 291189c..71898b0 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ namespace EFCoreSecondLevelCacheInterceptor.AspNetCoreSample { services.AddEFSecondLevelCache(options => options.UseMemoryCacheProvider().DisableLogging(true).UseCacheKeyPrefix("EF_") - // Fallback on db if the caching provider (redis) is down. + // Fallback on db if the caching provider fails. .UseDbCallsIfCachingProviderIsDown(TimeSpan.FromMinutes(1)) // Please use the `CacheManager.Core` or `EasyCaching.Redis` for the Redis cache provider. @@ -89,7 +89,7 @@ namespace EFSecondLevelCache.Core.AspNetCoreSample const string providerName1 = "InMemory1"; services.AddEFSecondLevelCache(options => options.UseEasyCachingCoreProvider(providerName1, isHybridCache: false).DisableLogging(true).UseCacheKeyPrefix("EF_") - // Fallback on db if the caching provider (redis) is down. + // Fallback on db if the caching provider fails. .UseDbCallsIfCachingProviderIsDown(TimeSpan.FromMinutes(1)) ); @@ -148,7 +148,7 @@ namespace EFSecondLevelCache.Core.AspNetCoreSample const string providerName1 = "Redis1"; services.AddEFSecondLevelCache(options => options.UseEasyCachingCoreProvider(providerName1, isHybridCache: false).DisableLogging(true).UseCacheKeyPrefix("EF_") - // Fallback on db if the caching provider (redis) is down. + // Fallback on db if the caching provider fails (for example, if Redis is down). .UseDbCallsIfCachingProviderIsDown(TimeSpan.FromMinutes(1)) ); @@ -203,7 +203,7 @@ services.AddEFSecondLevelCache(options => .UseCacheKeyPrefix(serviceProvider => "EF_" + serviceProvider.GetRequiredService().HttpContext.Request.Headers["tenant-id"]) .DisableLogging(true) .UseCacheKeyPrefix("EF_") - // Fallback on db if the caching provider (redis) is down. + // Fallback on db if the caching provider fails. .UseDbCallsIfCachingProviderIsDown(TimeSpan.FromMinutes(1)) ); ``` @@ -233,7 +233,7 @@ namespace EFSecondLevelCache.Core.AspNetCoreSample { services.AddEFSecondLevelCache(options => options.UseCacheManagerCoreProvider().DisableLogging(true).UseCacheKeyPrefix("EF_") - // Fallback on db if the caching provider (redis) is down. + // Fallback on db if the caching provider fails. .UseDbCallsIfCachingProviderIsDown(TimeSpan.FromMinutes(1)) ); @@ -285,7 +285,7 @@ services.AddSingleton(typeof(ICacheManager<>), typeof(BaseCacheManager<>)); services.AddEFSecondLevelCache(options => options.UseCacheManagerCoreProvider().DisableLogging(true).UseCacheKeyPrefix("EF_") - // Fallback on db if the caching provider (redis) is down. + // Fallback on db if the caching provider fails. .UseDbCallsIfCachingProviderIsDown(TimeSpan.FromMinutes(1)) ); ``` @@ -363,7 +363,7 @@ Also it's possible to set the `Cacheable()` method's settings globally: ```csharp services.AddEFSecondLevelCache(options => options.UseMemoryCacheProvider(CacheExpirationMode.Absolute, TimeSpan.FromMinutes(5)).DisableLogging(true) .UseCacheKeyPrefix("EF_") - // Fallback on db if the caching provider (redis) is down. + // Fallback on db if the caching provider fails. .UseDbCallsIfCachingProviderIsDown(TimeSpan.FromMinutes(1)) ); ``` @@ -395,7 +395,7 @@ namespace EFCoreSecondLevelCacheInterceptor.AspNetCoreSample { options.UseMemoryCacheProvider().DisableLogging(true).UseCacheKeyPrefix("EF_"); options.CacheAllQueries(CacheExpirationMode.Absolute, TimeSpan.FromMinutes(30)); - // Fallback on db if the caching provider (redis) is down. + // Fallback on db if the caching provider fails. options.UseDbCallsIfCachingProviderIsDown(TimeSpan.FromMinutes(1)); }); @@ -418,7 +418,7 @@ namespace EFCoreSecondLevelCacheInterceptor.AspNetCoreSample services.AddEFSecondLevelCache(options => { options.UseMemoryCacheProvider().DisableLogging(true).UseCacheKeyPrefix("EF_") - // Fallback on db if the caching provider (redis) is down. + // Fallback on db if the caching provider fails. .UseDbCallsIfCachingProviderIsDown(TimeSpan.FromMinutes(1)) /*.CacheQueriesContainingTypes( CacheExpirationMode.Absolute, TimeSpan.FromMinutes(30), TableTypeComparison.Contains, @@ -449,7 +449,7 @@ namespace EFCoreSecondLevelCacheInterceptor.AspNetCoreSample services.AddEFSecondLevelCache(options => { options.UseMemoryCacheProvider().DisableLogging(true).UseCacheKeyPrefix("EF_") - // Fallback on db if the caching provider (redis) is down. + // Fallback on db if the caching provider fails. .UseDbCallsIfCachingProviderIsDown(TimeSpan.FromMinutes(1)) // How to skip caching specific commands .SkipCachingCommands(commandText => @@ -472,7 +472,7 @@ namespace EFCoreSecondLevelCacheInterceptor.AspNetCoreSample services.AddEFSecondLevelCache(options => { options.UseMemoryCacheProvider().DisableLogging(true).UseCacheKeyPrefix("EF_") - // Fallback on db if the caching provider (redis) is down. + // Fallback on db if the caching provider fails. .UseDbCallsIfCachingProviderIsDown(TimeSpan.FromMinutes(1)) // Don't cache null values. Remove this optional setting if it's not necessary. .SkipCachingResults(result => @@ -495,7 +495,7 @@ namespace EFCoreSecondLevelCacheInterceptor.AspNetCoreSample services.AddEFSecondLevelCache(options => { options.UseMemoryCacheProvider().DisableLogging(true).UseCacheKeyPrefix("EF_") - // Fallback on db if the caching provider (redis) is down. + // Fallback on db if the caching provider fails. .UseDbCallsIfCachingProviderIsDown(TimeSpan.FromMinutes(1)) /*.CacheAllQueriesExceptContainingTypes( CacheExpirationMode.Absolute, TimeSpan.FromMinutes(30), @@ -526,7 +526,7 @@ namespace EFCoreSecondLevelCacheInterceptor.AspNetCoreSample services.AddEFSecondLevelCache(options => { options.UseMemoryCacheProvider().DisableLogging(true).UseCacheKeyPrefix("EF_") - // Fallback on db if the caching provider (redis) is down. + // Fallback on db if the caching provider fails. .UseDbCallsIfCachingProviderIsDown(TimeSpan.FromMinutes(1)) .SkipCacheInvalidationCommands(commandText => // How to skip invalidating the related cache entries of this query @@ -564,7 +564,7 @@ First set the `DisableLogging(false)`: ```c# services.AddEFSecondLevelCache(options => options.UseMemoryCacheProvider().DisableLogging(false).UseCacheKeyPrefix("EF_") - // Fallback on db if the caching provider (redis) is down. + // Fallback on db if the caching provider fails. .UseDbCallsIfCachingProviderIsDown(TimeSpan.FromMinutes(1)) ``` From f278db8a47e42dae959c83c76a9ce7f946119425 Mon Sep 17 00:00:00 2001 From: Peter Morlion Date: Fri, 26 Jan 2024 08:36:59 +0100 Subject: [PATCH 2/3] Correct title levels --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 71898b0..3abbb18 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ namespace EFCoreSecondLevelCacheInterceptor.AspNetCoreSample } ``` -### Using EasyCaching.Core as the cache provider +#### Using EasyCaching.Core as the cache provider Here you can use the [EasyCaching.Core](https://github.com/dotnetcore/EasyCaching), as a highly configurable cache manager too. To use its in-memory caching mechanism, add this entry to the `.csproj` file: @@ -190,7 +190,7 @@ namespace EFSecondLevelCache.Core.AspNetCoreSample [Here is a sample about it](/src/Tests/Issues/Issue123WithMessagePack/EFServiceProvider.cs). -### Using EasyCaching.Core as a dynamic cache provider +#### Using EasyCaching.Core as a dynamic cache provider If you want to support multitenancy in your application and have a different Redis database per each tenant, first register multiple pre-configured providers with known `providerName`s and then select these `providerName`s based on the current tenant this way dynamically: @@ -209,7 +209,7 @@ services.AddEFSecondLevelCache(options => ``` -### Using CacheManager.Core as the cache provider [It's not actively maintained] +#### Using CacheManager.Core as the cache provider [It's not actively maintained] Also here you can use the [CacheManager.Core](https://github.com/MichaCo/CacheManager), as a highly configurable cache manager too. To use its in-memory caching mechanism, add these entries to the `.csproj` file: @@ -292,7 +292,7 @@ services.AddEFSecondLevelCache(options => [Here is](/src/Tests/EFCoreSecondLevelCacheInterceptor.Tests/Settings/EFServiceProvider.cs#L21) the definition of the SpecialTypesConverter. -### Using a custom cache provider +#### Using a custom cache provider If you don't want to use the above cache providers, implement your custom `IEFCacheServiceProvider` and then introduce it using the `options.UseCustomCacheProvider()` method. From f3401df65f277b59b5d45cb8cfbc26ecd6306f87 Mon Sep 17 00:00:00 2001 From: Peter Morlion Date: Fri, 26 Jan 2024 08:42:15 +0100 Subject: [PATCH 3/3] Add an overview of the possible cache providers --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 3abbb18..440869c 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,14 @@ You can also view the [package page](http://www.nuget.org/packages/EFCoreSecondL ### 1- [Register a preferred cache provider](/src/Tests/EFCoreSecondLevelCacheInterceptor.AspNetCoreSample/Startup.cs): +You can use the following cache providers: + +- [Memory provider built in this library](#using-the-built-in-In-Memory-cache-provider) +- [EasyCaching.Core memory provider](#Using-EasyCaching.Core-as-the-cache-provider) +- [EasyCaching.Core dynamic cache provider](#Using-EasyCaching.Core-as-a-dynamic-cache-provider) +- [CacheManager.Core cache provider](#Using-CacheManager.Core-as-the-cache-provider-\[It's-not-actively-maintained\]) +- [A custom cache provider](#Using-a-custom-cache-provider)] + #### Using the built-in In-Memory cache provider ![performance](/src/Tests/EFCoreSecondLevelCacheInterceptor.PerformanceTests/int-pref.png)