-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
DistributedCacheEntryExtensions.cs
53 lines (49 loc) · 2.06 KB
/
DistributedCacheEntryExtensions.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
namespace Microsoft.Extensions.Caching.Distributed
{
/// <summary>
/// Extension methods for <see cref="DistributedCacheEntryOptions"/> operations.
/// </summary>
public static class DistributedCacheEntryExtensions
{
/// <summary>
/// Sets an absolute expiration time, relative to now.
/// </summary>
/// <param name="options">The options to be operated on.</param>
/// <param name="relative">The expiration time, relative to now.</param>
public static DistributedCacheEntryOptions SetAbsoluteExpiration(
this DistributedCacheEntryOptions options,
TimeSpan relative)
{
options.AbsoluteExpirationRelativeToNow = relative;
return options;
}
/// <summary>
/// Sets an absolute expiration date for the cache entry.
/// </summary>
/// <param name="options">The options to be operated on.</param>
/// <param name="absolute">The expiration time, in absolute terms.</param>
public static DistributedCacheEntryOptions SetAbsoluteExpiration(
this DistributedCacheEntryOptions options,
DateTimeOffset absolute)
{
options.AbsoluteExpiration = absolute;
return options;
}
/// <summary>
/// Sets how long the cache entry can be inactive (e.g. not accessed) before it will be removed.
/// This will not extend the entry lifetime beyond the absolute expiration (if set).
/// </summary>
/// <param name="options">The options to be operated on.</param>
/// <param name="offset">The sliding expiration time.</param>
public static DistributedCacheEntryOptions SetSlidingExpiration(
this DistributedCacheEntryOptions options,
TimeSpan offset)
{
options.SlidingExpiration = offset;
return options;
}
}
}