Browse Source
Merge pull request #5694 from RachaneeSaeng/dev
Add appsettings to enable/disable Redis as distributed cache
pull/5759/head
Halil İbrahim Kalkan
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
14 additions and
8 deletions
docs/en/Redis-Cache.md
framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpCachingStackExchangeRedisModule.cs
@ -25,9 +25,11 @@ Volo.Abp.Caching.StackExchangeRedis package automatically gets the redis [config
````js
"Redis": {
"IsEnabled": "true",
"Configuration": "127.0.0.1"
}
````
The setting `IsEnabled` is optional and will be considered `true` if it is not set.
Alternatively you can configure the standard [RedisCacheOptions ](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.stackexchangeredis.rediscacheoptions ) [options ](Options.md ) class in the `ConfigureServices` method of your [module ](Module-Development-Basics.md ):
@ -14,17 +14,21 @@ namespace Volo.Abp.Caching.StackExchangeRedis
public override void ConfigureServices ( ServiceConfigurationContext context )
{
var configuration = context . Services . GetConfiguration ( ) ;
context . Services . AddStackExchangeRedisCache ( options = >
var redisEnabled = configuration [ "Redis:IsEnabled" ] ;
if ( redisEnabled . IsNullOrEmpty ( ) | | bool . Parse ( redisEnabled ) )
{
var redisConfiguration = configuration [ "Redis:Configuration" ] ;
if ( ! redisConfiguration . IsNullOrEmpty ( ) )
context . Services . AddStackExchangeRedisCache ( options = >
{
options . Configuration = configuration [ "Redis:Configuration" ] ;
}
} ) ;
var redisConfiguration = configuration [ "Redis:Configuration" ] ;
if ( ! redisConfiguration . IsNullOrEmpty ( ) )
{
options . Configuration = redisConfiguration ;
}
} ) ;
context . Services . Replace ( ServiceDescriptor . Singleton < IDistributedCache , AbpRedisCache > ( ) ) ;
context . Services . Replace ( ServiceDescriptor . Singleton < IDistributedCache , AbpRedisCache > ( ) ) ;
}
}
}
}