|
5 | 5 | using System.Net.Http.Formatting; |
6 | 6 | using System.Net.Http.Headers; |
7 | 7 | using System.Runtime.ExceptionServices; |
| 8 | +using System.Runtime.InteropServices; |
8 | 9 | using System.Text; |
9 | 10 | using System.Threading; |
10 | 11 | using System.Threading.Tasks; |
@@ -48,6 +49,23 @@ public class CacheOutputAttribute : ActionFilterAttribute |
48 | 49 | /// </summary> |
49 | 50 | public int ClientTimeSpan { get; set; } |
50 | 51 |
|
| 52 | + |
| 53 | + private int? _sharedTimeSpan = null; |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// Corresponds to CacheControl Shared MaxAge HTTP header (in seconds) |
| 57 | + /// </summary> |
| 58 | + public int SharedTimeSpan |
| 59 | + { |
| 60 | + get // required for property visibility |
| 61 | + { |
| 62 | + if (!_sharedTimeSpan.HasValue) |
| 63 | + throw new Exception("should not be called without value set"); |
| 64 | + return _sharedTimeSpan.Value; |
| 65 | + } |
| 66 | + set { _sharedTimeSpan = value; } |
| 67 | + } |
| 68 | + |
51 | 69 | /// <summary> |
52 | 70 | /// Corresponds to CacheControl NoCache HTTP header |
53 | 71 | /// </summary> |
@@ -98,7 +116,7 @@ protected virtual void EnsureCacheTimeQuery() |
98 | 116 |
|
99 | 117 | protected void ResetCacheTimeQuery() |
100 | 118 | { |
101 | | - CacheTimeQuery = new ShortTime( ServerTimeSpan, ClientTimeSpan ); |
| 119 | + CacheTimeQuery = new ShortTime( ServerTimeSpan, ClientTimeSpan, _sharedTimeSpan); |
102 | 120 | } |
103 | 121 |
|
104 | 122 | protected virtual MediaTypeHeaderValue GetExpectedMediaType(HttpConfiguration config, HttpActionContext actionContext) |
@@ -247,6 +265,7 @@ protected virtual void ApplyCacheHeaders(HttpResponseMessage response, CacheTime |
247 | 265 | var cachecontrol = new CacheControlHeaderValue |
248 | 266 | { |
249 | 267 | MaxAge = cacheTime.ClientTimeSpan, |
| 268 | + SharedMaxAge = cacheTime.SharedTimeSpan, |
250 | 269 | MustRevalidate = MustRevalidate, |
251 | 270 | Private = Private |
252 | 271 | }; |
|
0 commit comments