|
2 | 2 | // Licensed under the MIT License. See LICENSE.txt in the project root for license information.
|
3 | 3 |
|
4 | 4 | // ReSharper disable once CheckNamespace
|
5 |
| -namespace Masa.BuildingBlocks.Caching |
6 |
| -{ |
7 |
| - public class CacheEntryOptions |
8 |
| - { |
9 |
| - private TimeSpan? _absoluteExpirationRelativeToNow; |
10 |
| - private TimeSpan? _slidingExpiration; |
11 | 5 |
|
12 |
| - /// <summary> |
13 |
| - /// Gets or sets an absolute expiration date for the cache entry. |
14 |
| - /// When coexisting with AbsoluteExpirationRelativeToNow, use AbsoluteExpirationRelativeToNow first |
15 |
| - /// </summary> |
16 |
| - public DateTimeOffset? AbsoluteExpiration { get; set; } |
| 6 | +namespace Masa.BuildingBlocks.Caching; |
17 | 7 |
|
18 |
| - /// <summary> |
19 |
| - /// Gets or sets an absolute expiration time, relative to now. |
20 |
| - /// When coexisting with AbsoluteExpiration, use AbsoluteExpirationRelativeToNow first |
21 |
| - /// </summary> |
22 |
| - public TimeSpan? AbsoluteExpirationRelativeToNow |
23 |
| - { |
24 |
| - get => _absoluteExpirationRelativeToNow; |
25 |
| - set |
26 |
| - { |
27 |
| - if (value <= TimeSpan.Zero) |
28 |
| - { |
29 |
| - throw new ArgumentOutOfRangeException( |
30 |
| - nameof(AbsoluteExpirationRelativeToNow), |
31 |
| - value, |
32 |
| - "The relative expiration value must be positive."); |
33 |
| - } |
| 8 | +public class CacheEntryOptions |
| 9 | +{ |
| 10 | + private TimeSpan? _absoluteExpirationRelativeToNow; |
| 11 | + private TimeSpan? _slidingExpiration; |
34 | 12 |
|
35 |
| - _absoluteExpirationRelativeToNow = value; |
36 |
| - } |
37 |
| - } |
| 13 | + /// <summary> |
| 14 | + /// Gets or sets an absolute expiration date for the cache entry. |
| 15 | + /// When coexisting with AbsoluteExpirationRelativeToNow, use AbsoluteExpirationRelativeToNow first |
| 16 | + /// </summary> |
| 17 | + public DateTimeOffset? AbsoluteExpiration { get; set; } |
38 | 18 |
|
39 |
| - /// <summary> |
40 |
| - /// Gets or sets how long a cache entry can be inactive (e.g. not accessed) before it will be removed. |
41 |
| - /// This will not extend the entry lifetime beyond the absolute expiration (if set). |
42 |
| - /// </summary> |
43 |
| - public TimeSpan? SlidingExpiration |
| 19 | + /// <summary> |
| 20 | + /// Gets or sets an absolute expiration time, relative to now. |
| 21 | + /// When coexisting with AbsoluteExpiration, use AbsoluteExpirationRelativeToNow first |
| 22 | + /// </summary> |
| 23 | + public TimeSpan? AbsoluteExpirationRelativeToNow |
| 24 | + { |
| 25 | + get => _absoluteExpirationRelativeToNow; |
| 26 | + set |
44 | 27 | {
|
45 |
| - get => _slidingExpiration; |
46 |
| - set |
| 28 | + if (value <= TimeSpan.Zero) |
47 | 29 | {
|
48 |
| - if (value <= TimeSpan.Zero) |
49 |
| - { |
50 |
| - throw new ArgumentOutOfRangeException( |
51 |
| - nameof(SlidingExpiration), |
52 |
| - value, |
53 |
| - "The sliding expiration value must be positive."); |
54 |
| - } |
55 |
| - _slidingExpiration = value; |
| 30 | + throw new ArgumentOutOfRangeException( |
| 31 | + nameof(AbsoluteExpirationRelativeToNow), |
| 32 | + value, |
| 33 | + "The relative expiration value must be positive."); |
56 | 34 | }
|
57 |
| - } |
58 |
| - |
59 |
| - public CacheEntryOptions() { } |
60 |
| - |
61 |
| - public CacheEntryOptions(DateTimeOffset? absoluteExpiration) |
62 |
| - => AbsoluteExpiration = absoluteExpiration; |
63 | 35 |
|
64 |
| - public CacheEntryOptions(TimeSpan? absoluteExpirationRelativeToNow) |
65 |
| - => AbsoluteExpirationRelativeToNow = absoluteExpirationRelativeToNow; |
| 36 | + _absoluteExpirationRelativeToNow = value; |
| 37 | + } |
66 | 38 | }
|
67 | 39 |
|
68 |
| - public class CacheEntryOptions<T> : CacheEntryOptions |
| 40 | + /// <summary> |
| 41 | + /// Gets or sets how long a cache entry can be inactive (e.g. not accessed) before it will be removed. |
| 42 | + /// This will not extend the entry lifetime beyond the absolute expiration (if set). |
| 43 | + /// </summary> |
| 44 | + public TimeSpan? SlidingExpiration |
69 | 45 | {
|
70 |
| - public Action<T?>? ValueChanged { get; set; } |
71 |
| - |
72 |
| - public CacheEntryOptions() |
| 46 | + get => _slidingExpiration; |
| 47 | + set |
73 | 48 | {
|
| 49 | + if (value <= TimeSpan.Zero) |
| 50 | + { |
| 51 | + throw new ArgumentOutOfRangeException( |
| 52 | + nameof(SlidingExpiration), |
| 53 | + value, |
| 54 | + "The sliding expiration value must be positive."); |
| 55 | + } |
| 56 | + _slidingExpiration = value; |
74 | 57 | }
|
| 58 | + } |
75 | 59 |
|
76 |
| - public CacheEntryOptions(DateTimeOffset? absoluteExpiration) : base(absoluteExpiration) |
77 |
| - { |
78 |
| - } |
| 60 | + public CacheEntryOptions() { } |
79 | 61 |
|
80 |
| - public CacheEntryOptions(TimeSpan? absoluteExpirationRelativeToNow) : base(absoluteExpirationRelativeToNow) |
81 |
| - { |
| 62 | + public CacheEntryOptions(DateTimeOffset? absoluteExpiration) |
| 63 | + => AbsoluteExpiration = absoluteExpiration; |
82 | 64 |
|
83 |
| - } |
84 |
| - } |
| 65 | + public CacheEntryOptions(TimeSpan? absoluteExpirationRelativeToNow) |
| 66 | + => AbsoluteExpirationRelativeToNow = absoluteExpirationRelativeToNow; |
85 | 67 | }
|
0 commit comments