1- namespace DotNetToolkit . Repository . Caching . Redis
1+ namespace DotNetToolkit . Repository . Caching . Redis . Internal
22{
33 using Configuration . Caching ;
44 using Newtonsoft . Json ;
@@ -12,6 +12,9 @@ internal class RedisCacheProvider : ICacheProvider
1212
1313 private IDatabase _redis ;
1414 private readonly Lazy < ConnectionMultiplexer > _lazyConnection ;
15+ private readonly JsonSerializerSettings _serializerSettings ;
16+
17+ private const string DefaultHost = "localhost" ;
1518
1619 #endregion
1720
@@ -25,17 +28,18 @@ internal class RedisCacheProvider : ICacheProvider
2528
2629 #region Constructors
2730
28- public RedisCacheProvider ( )
29- : this ( "localhost" , null , null , false , false , null , null ) { }
31+ public RedisCacheProvider ( JsonSerializerSettings serializerSettings = null )
32+ : this ( DefaultHost , null , null , false , false , null , null , serializerSettings ) { }
3033
31- public RedisCacheProvider ( string host , string username , string password , bool ssl , bool allowAdmin , int ? defaultDatabase , TimeSpan ? expiry )
32- : this ( GetConfigurationOptions ( host , username , password , ssl , allowAdmin , defaultDatabase ) , expiry ) { }
34+ public RedisCacheProvider ( string host , string username , string password , bool ssl , bool allowAdmin , int ? defaultDatabase , TimeSpan ? expiry , JsonSerializerSettings serializerSettings )
35+ : this ( GetConfigurationOptions ( host , username , password , ssl , allowAdmin , defaultDatabase ) , expiry , serializerSettings ) { }
3336
34- private RedisCacheProvider ( ConfigurationOptions options , TimeSpan ? expiry )
37+ private RedisCacheProvider ( ConfigurationOptions options , TimeSpan ? expiry , JsonSerializerSettings serializerSettings = null )
3538 {
3639 Guard . NotNull ( options , nameof ( options ) ) ;
3740
3841 _lazyConnection = new Lazy < ConnectionMultiplexer > ( ( ) => ConnectionMultiplexer . Connect ( options ) ) ;
42+ _serializerSettings = serializerSettings ;
3943
4044 Expiry = expiry ;
4145 }
@@ -44,20 +48,20 @@ private RedisCacheProvider(ConfigurationOptions options, TimeSpan? expiry)
4448
4549 #region Private Methods
4650
47- private static string Serialize ( object o )
51+ private string Serialize ( object o )
4852 {
4953 if ( o == null )
5054 return null ;
5155
52- return JsonConvert . SerializeObject ( o ) ;
56+ return JsonConvert . SerializeObject ( o , _serializerSettings ) ;
5357 }
5458
55- private static T Deserialize < T > ( string v )
59+ private T Deserialize < T > ( string v )
5660 {
5761 if ( string . IsNullOrEmpty ( v ) )
5862 return default ( T ) ;
5963
60- return JsonConvert . DeserializeObject < T > ( v ) ;
64+ return JsonConvert . DeserializeObject < T > ( v , _serializerSettings ) ;
6165 }
6266
6367 private static ConfigurationOptions GetConfigurationOptions ( string host , string username , string password , bool ssl , bool allowAdmin , int ? defaultDatabase )
0 commit comments