@@ -205,6 +205,7 @@ public override void OnActionExecuting(HttpActionContext actionContext)
205
205
if ( val == null ) return ;
206
206
207
207
var contenttype = _webApiCache . Get < MediaTypeHeaderValue > ( cachekey + Constants . ContentTypeKey ) ?? responseMediaType ;
208
+ var contentGenerationTimestamp = DateTimeOffset . Parse ( _webApiCache . Get < string > ( cachekey + Constants . GenerationTimestampKey ) ) ;
208
209
209
210
actionContext . Response = actionContext . Request . CreateResponse ( ) ;
210
211
actionContext . Response . Content = new ByteArrayContent ( val ) ;
@@ -214,7 +215,7 @@ public override void OnActionExecuting(HttpActionContext actionContext)
214
215
if ( responseEtag != null ) SetEtag ( actionContext . Response , responseEtag ) ;
215
216
216
217
var cacheTime = CacheTimeQuery . Execute ( DateTime . Now ) ;
217
- ApplyCacheHeaders ( actionContext . Response , cacheTime ) ;
218
+ ApplyCacheHeaders ( actionContext . Response , cacheTime , contentGenerationTimestamp ) ;
218
219
}
219
220
220
221
public override async Task OnActionExecutedAsync ( HttpActionExecutedContext actionExecutedContext , CancellationToken cancellationToken )
@@ -223,8 +224,9 @@ public override async Task OnActionExecutedAsync(HttpActionExecutedContext actio
223
224
224
225
if ( ! IsCachingAllowed ( actionExecutedContext . ActionContext , AnonymousOnly ) ) return ;
225
226
226
- var cacheTime = CacheTimeQuery . Execute ( DateTime . Now ) ;
227
- if ( cacheTime . AbsoluteExpiration > DateTime . Now )
227
+ var actionExecutionTimestamp = DateTimeOffset . Now ;
228
+ var cacheTime = CacheTimeQuery . Execute ( actionExecutionTimestamp . DateTime ) ;
229
+ if ( cacheTime . AbsoluteExpiration > actionExecutionTimestamp )
228
230
{
229
231
var httpConfig = actionExecutedContext . Request . GetConfiguration ( ) ;
230
232
var config = httpConfig . CacheOutputConfiguration ( ) ;
@@ -261,14 +263,19 @@ public override async Task OnActionExecutedAsync(HttpActionExecutedContext actio
261
263
_webApiCache . Add ( cachekey + Constants . EtagKey ,
262
264
etag ,
263
265
cacheTime . AbsoluteExpiration , baseKey ) ;
266
+
267
+
268
+ _webApiCache . Add ( cachekey + Constants . GenerationTimestampKey ,
269
+ actionExecutionTimestamp . ToString ( ) ,
270
+ cacheTime . AbsoluteExpiration , baseKey ) ;
264
271
}
265
272
}
266
273
}
267
274
268
- ApplyCacheHeaders ( actionExecutedContext . ActionContext . Response , cacheTime ) ;
275
+ ApplyCacheHeaders ( actionExecutedContext . ActionContext . Response , cacheTime , actionExecutionTimestamp ) ;
269
276
}
270
277
271
- protected virtual void ApplyCacheHeaders ( HttpResponseMessage response , CacheTime cacheTime )
278
+ protected virtual void ApplyCacheHeaders ( HttpResponseMessage response , CacheTime cacheTime , DateTimeOffset ? contentGenerationTimestamp = null )
272
279
{
273
280
if ( cacheTime . ClientTimeSpan > TimeSpan . Zero || MustRevalidate || Private )
274
281
{
@@ -287,6 +294,10 @@ protected virtual void ApplyCacheHeaders(HttpResponseMessage response, CacheTime
287
294
response . Headers . CacheControl = new CacheControlHeaderValue { NoCache = true } ;
288
295
response . Headers . Add ( "Pragma" , "no-cache" ) ;
289
296
}
297
+ if ( ( response . Content != null ) && contentGenerationTimestamp . HasValue )
298
+ {
299
+ response . Content . Headers . LastModified = contentGenerationTimestamp . Value ;
300
+ }
290
301
}
291
302
292
303
protected virtual string CreateEtag ( HttpActionExecutedContext actionExecutedContext , string cachekey , CacheTime cacheTime )
0 commit comments