Skip to content

Commit e84b4a1

Browse files
committed
Possibility to override eTag-creation for custom caching rules. See: meerikss@2811ff0
1 parent 85fb433 commit e84b4a1

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/WebAPI.OutputCache/CacheOutputAttribute.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public override void OnActionExecuted(HttpActionExecutedContext actionExecutedCo
180180
{
181181
var response = actionExecutedContext.Response;
182182
var actionContext = actionExecutedContext.ActionContext;
183-
SetEtag(response, Guid.NewGuid().ToString());
183+
SetEtag(response, CreateEtag(actionExecutedContext, cachekey, cacheTime));
184184

185185

186186
if (response.Content != null)
@@ -207,6 +207,11 @@ public override void OnActionExecuted(HttpActionExecutedContext actionExecutedCo
207207
ApplyCacheHeaders(actionExecutedContext.ActionContext.Response, cacheTime);
208208
}
209209

210+
protected virtual string CreateEtag(HttpActionExecutedContext actionExecutedContext, string cachekey, CacheTime cacheTime)
211+
{
212+
return Guid.NewGuid().ToString();
213+
}
214+
210215
private void ApplyCacheHeaders(HttpResponseMessage response, CacheTime cacheTime)
211216
{
212217
if (cacheTime.ClientTimeSpan > TimeSpan.Zero || MustRevalidate || Private)

src/WebApi.OutputCache.V2/CacheOutputAttribute.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ private async Task OnActionExecuted(HttpActionExecutedContext actionExecutedCont
191191

192192
if (!string.IsNullOrWhiteSpace(cachekey) && !(_webApiCache.Contains(cachekey)))
193193
{
194-
SetEtag(actionExecutedContext.Response, Guid.NewGuid().ToString());
194+
SetEtag(actionExecutedContext.Response, CreateEtag(actionExecutedContext, cachekey, cacheTime));
195195

196196
var responseContent = actionExecutedContext.Response.Content;
197197

@@ -244,6 +244,11 @@ protected virtual void ApplyCacheHeaders(HttpResponseMessage response, CacheTime
244244
}
245245
}
246246

247+
protected virtual string CreateEtag(HttpActionExecutedContext actionExecutedContext, string cachekey, CacheTime cacheTime)
248+
{
249+
return Guid.NewGuid().ToString();
250+
}
251+
247252
private static void SetEtag(HttpResponseMessage message, string etag)
248253
{
249254
if (etag != null)

0 commit comments

Comments
 (0)