/
CacheInfo.cs
84 lines (69 loc) · 2.28 KB
/
CacheInfo.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
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
namespace ServiceStack;
public class CacheInfo
{
/// <summary>
/// The CacheKey to be use store the response against
/// </summary>
public string CacheKey => KeyBase + KeyModifiers;
/// <summary>
/// The base Cache Key used to cache the Service response
/// </summary>
public string KeyBase { get; set; }
/// <summary>
/// Additional CacheKey Modifiers used to cache different outputs for a single Service Response
/// </summary>
public string KeyModifiers { get; set; }
/// <summary>
/// How long to cache the resource for. Fallsback to HttpCacheFeature.DefaultExpiresIn
/// </summary>
public TimeSpan? ExpiresIn { get; set; }
/// <summary>
/// The unique ETag returned for this resource clients can use to determine whether their local version has changed
/// </summary>
public string ETag { get; set; }
/// <summary>
/// The Age for this resource returned to clients
/// </summary>
public TimeSpan? Age { get; set; }
/// <summary>
/// The MaxAge returned to clients to indicate how long they can use their local cache before re-validating
/// </summary>
public TimeSpan? MaxAge { get; set; }
/// <summary>
/// The LastModified date to use for the Cache and HTTP Header
/// </summary>
public DateTime? LastModified { get; set; }
/// <summary>
/// Cache-Control HTTP Headers
/// </summary>
public CacheControl CacheControl { get; set; }
/// <summary>
/// Create unique cache per user
/// </summary>
public bool VaryByUser { get; set; }
/// <summary>
/// Use HostContext.LocalCache or HostContext.Cache
/// </summary>
public bool LocalCache { get; set; }
/// <summary>
/// Skip compression for this Cache Result
/// </summary>
public bool NoCompression { get; set; }
}
public static class CacheInfoExtensions
{
public static CacheInfo ToCacheInfo(this HttpResult httpResult)
{
if (httpResult == null)
return null;
return new CacheInfo
{
ETag = httpResult.ETag,
Age = httpResult.Age,
MaxAge = httpResult.MaxAge,
LastModified = httpResult.LastModified,
CacheControl = httpResult.CacheControl,
};
}
}