-
Notifications
You must be signed in to change notification settings - Fork 106
/
ComputedOptions.cs
45 lines (40 loc) · 1.72 KB
/
ComputedOptions.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
using System;
using Newtonsoft.Json;
namespace Stl.Fusion
{
[Serializable]
public class ComputedOptions
{
public static readonly TimeSpan DefaultKeepAliveTime = TimeSpan.Zero;
public static readonly TimeSpan DefaultErrorAutoInvalidateTime = TimeSpan.FromSeconds(1);
public static readonly TimeSpan DefaultAutoInvalidateTime = TimeSpan.MaxValue; // No auto invalidation
public static readonly ComputedOptions Default = new ComputedOptions();
public static readonly ComputedOptions NoAutoInvalidateOnError =
new ComputedOptions(errorAutoInvalidateTime: TimeSpan.MaxValue);
public TimeSpan KeepAliveTime { get; }
public TimeSpan ErrorAutoInvalidateTime { get; }
public TimeSpan AutoInvalidateTime { get; }
public ComputedOptions(
TimeSpan? keepAliveTime = null,
TimeSpan? errorAutoInvalidateTime = null,
TimeSpan? autoInvalidateTime = null)
: this(
keepAliveTime ?? DefaultKeepAliveTime,
errorAutoInvalidateTime ?? DefaultErrorAutoInvalidateTime,
autoInvalidateTime ?? DefaultAutoInvalidateTime)
{ }
[JsonConstructor]
public ComputedOptions(
TimeSpan keepAliveTime,
TimeSpan errorAutoInvalidateTime,
TimeSpan autoInvalidateTime)
{
KeepAliveTime = keepAliveTime;
ErrorAutoInvalidateTime = errorAutoInvalidateTime;
AutoInvalidateTime = autoInvalidateTime;
if (ErrorAutoInvalidateTime > autoInvalidateTime)
// It just doesn't make sense to keep it higher
ErrorAutoInvalidateTime = autoInvalidateTime;
}
}
}