@@ -195,6 +195,7 @@ public override void OnActionExecuting(HttpActionContext actionContext)
195
195
if ( val == null ) return ;
196
196
197
197
var contenttype = _webApiCache . Get < MediaTypeHeaderValue > ( cachekey + Constants . ContentTypeKey ) ?? responseMediaType ;
198
+ var contentGenerationTimestamp = DateTimeOffset . Parse ( _webApiCache . Get < string > ( cachekey + Constants . GenerationTimestampKey ) ) ;
198
199
199
200
actionContext . Response = actionContext . Request . CreateResponse ( ) ;
200
201
actionContext . Response . Content = new ByteArrayContent ( val ) ;
@@ -204,7 +205,7 @@ public override void OnActionExecuting(HttpActionContext actionContext)
204
205
if ( responseEtag != null ) SetEtag ( actionContext . Response , responseEtag ) ;
205
206
206
207
var cacheTime = CacheTimeQuery . Execute ( DateTime . Now ) ;
207
- ApplyCacheHeaders ( actionContext . Response , cacheTime ) ;
208
+ ApplyCacheHeaders ( actionContext . Response , cacheTime , contentGenerationTimestamp ) ;
208
209
}
209
210
210
211
public override async Task OnActionExecutedAsync ( HttpActionExecutedContext actionExecutedContext , CancellationToken cancellationToken )
@@ -213,8 +214,9 @@ public override async Task OnActionExecutedAsync(HttpActionExecutedContext actio
213
214
214
215
if ( ! IsCachingAllowed ( actionExecutedContext . ActionContext , AnonymousOnly ) ) return ;
215
216
216
- var cacheTime = CacheTimeQuery . Execute ( DateTime . Now ) ;
217
- if ( cacheTime . AbsoluteExpiration > DateTime . Now )
217
+ var actionExecutionTimestamp = DateTimeOffset . Now ;
218
+ var cacheTime = CacheTimeQuery . Execute ( actionExecutionTimestamp . DateTime ) ;
219
+ if ( cacheTime . AbsoluteExpiration > actionExecutionTimestamp )
218
220
{
219
221
var httpConfig = actionExecutedContext . Request . GetConfiguration ( ) ;
220
222
var config = httpConfig . CacheOutputConfiguration ( ) ;
@@ -251,14 +253,19 @@ public override async Task OnActionExecutedAsync(HttpActionExecutedContext actio
251
253
_webApiCache . Add ( cachekey + Constants . EtagKey ,
252
254
etag ,
253
255
cacheTime . AbsoluteExpiration , baseKey ) ;
256
+
257
+
258
+ _webApiCache . Add ( cachekey + Constants . GenerationTimestampKey ,
259
+ actionExecutionTimestamp . ToString ( ) ,
260
+ cacheTime . AbsoluteExpiration , baseKey ) ;
254
261
}
255
262
}
256
263
}
257
264
258
- ApplyCacheHeaders ( actionExecutedContext . ActionContext . Response , cacheTime ) ;
265
+ ApplyCacheHeaders ( actionExecutedContext . ActionContext . Response , cacheTime , actionExecutionTimestamp ) ;
259
266
}
260
267
261
- protected virtual void ApplyCacheHeaders ( HttpResponseMessage response , CacheTime cacheTime )
268
+ protected virtual void ApplyCacheHeaders ( HttpResponseMessage response , CacheTime cacheTime , DateTimeOffset ? contentGenerationTimestamp = null )
262
269
{
263
270
if ( cacheTime . ClientTimeSpan > TimeSpan . Zero || MustRevalidate || Private )
264
271
{
@@ -277,6 +284,10 @@ protected virtual void ApplyCacheHeaders(HttpResponseMessage response, CacheTime
277
284
response . Headers . CacheControl = new CacheControlHeaderValue { NoCache = true } ;
278
285
response . Headers . Add ( "Pragma" , "no-cache" ) ;
279
286
}
287
+ if ( ( response . Content != null ) && contentGenerationTimestamp . HasValue )
288
+ {
289
+ response . Content . Headers . LastModified = contentGenerationTimestamp . Value ;
290
+ }
280
291
}
281
292
282
293
protected virtual string CreateEtag ( HttpActionExecutedContext actionExecutedContext , string cachekey , CacheTime cacheTime )
0 commit comments