-
Notifications
You must be signed in to change notification settings - Fork 10.2k
/
Copy pathRedisCacheOptions.cs
71 lines (59 loc) · 2.25 KB
/
RedisCacheOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using StackExchange.Redis;
using StackExchange.Redis.Configuration;
using StackExchange.Redis.Profiling;
namespace Microsoft.Extensions.Caching.StackExchangeRedis;
/// <summary>
/// Configuration options for <see cref="RedisCache"/>.
/// </summary>
public class RedisCacheOptions : IOptions<RedisCacheOptions>
{
/// <summary>
/// The configuration used to connect to Redis.
/// </summary>
public string? Configuration { get; set; }
/// <summary>
/// The configuration used to connect to Redis.
/// This is preferred over Configuration.
/// </summary>
public ConfigurationOptions? ConfigurationOptions { get; set; }
/// <summary>
/// Gets or sets a delegate to create the ConnectionMultiplexer instance.
/// </summary>
public Func<Task<IConnectionMultiplexer>>? ConnectionMultiplexerFactory { get; set; }
/// <summary>
/// The Redis instance name. Allows partitioning a single backend cache for use with multiple apps/services.
/// If set, the cache keys are prefixed with this value.
/// </summary>
public string? InstanceName { get; set; }
/// <summary>
/// The Redis profiling session
/// </summary>
public Func<ProfilingSession>? ProfilingSession { get; set; }
RedisCacheOptions IOptions<RedisCacheOptions>.Value
{
get { return this; }
}
private bool? _useForceReconnect;
internal bool UseForceReconnect
{
get
{
return _useForceReconnect ??= GetDefaultValue();
static bool GetDefaultValue() =>
AppContext.TryGetSwitch("Microsoft.AspNetCore.Caching.StackExchangeRedis.UseForceReconnect", out var value) && value;
}
set => _useForceReconnect = value;
}
internal ConfigurationOptions GetConfiguredOptions()
{
var options = ConfigurationOptions ?? ConfigurationOptions.Parse(Configuration!);
// we don't want an initially unavailable server to prevent DI creating the service itself
options.AbortOnConnectFail = false;
return options;
}
}