@@ -204,7 +204,8 @@ public override async Task OnActionExecutingAsync(HttpActionContext actionContex
204204 var val = await _webApiCache . GetAsync < byte [ ] > ( cachekey ) ;
205205 if ( val == null ) return ;
206206
207- var contenttype = await _webApiCache . GetAsync < MediaTypeHeaderValue > ( cachekey + Constants . ContentTypeKey ) ?? responseMediaType ;
207+ var contenttype = await _webApiCache . GetAsync < MediaTypeHeaderValue > ( cachekey + Constants . ContentTypeKey ) ?? responseMediaType ;
208+ var contentGenerationTimestamp = DateTimeOffset . Parse ( await _webApiCache . GetAsync < string > ( cachekey + Constants . GenerationTimestampKey ) ) ;
208209
209210 actionContext . Response = actionContext . Request . CreateResponse ( ) ;
210211 actionContext . Response . Content = new ByteArrayContent ( val ) ;
@@ -214,7 +215,7 @@ public override async Task OnActionExecutingAsync(HttpActionContext actionContex
214215 if ( responseEtag != null ) SetEtag ( actionContext . Response , responseEtag ) ;
215216
216217 var cacheTime = CacheTimeQuery . Execute ( DateTime . Now ) ;
217- ApplyCacheHeaders ( actionContext . Response , cacheTime ) ;
218+ ApplyCacheHeaders ( actionContext . Response , cacheTime , contentGenerationTimestamp ) ;
218219 }
219220
220221 public override async Task OnActionExecutedAsync ( HttpActionExecutedContext actionExecutedContext , CancellationToken cancellationToken )
@@ -223,8 +224,9 @@ public override async Task OnActionExecutedAsync(HttpActionExecutedContext actio
223224
224225 if ( ! IsCachingAllowed ( actionExecutedContext . ActionContext , AnonymousOnly ) ) return ;
225226
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 )
228230 {
229231 var httpConfig = actionExecutedContext . Request . GetConfiguration ( ) ;
230232 var config = httpConfig . CacheOutputConfiguration ( ) ;
@@ -259,14 +261,19 @@ await _webApiCache.AddAsync(cachekey + Constants.ContentTypeKey,
259261 await _webApiCache . AddAsync ( cachekey + Constants . EtagKey ,
260262 etag ,
261263 cacheTime . AbsoluteExpiration , baseKey ) ;
264+
265+
266+ await _webApiCache . AddAsync ( cachekey + Constants . GenerationTimestampKey ,
267+ actionExecutionTimestamp . ToString ( ) ,
268+ cacheTime . AbsoluteExpiration , baseKey ) ;
262269 }
263270 }
264271 }
265272
266- ApplyCacheHeaders ( actionExecutedContext . ActionContext . Response , cacheTime ) ;
273+ ApplyCacheHeaders ( actionExecutedContext . ActionContext . Response , cacheTime , actionExecutionTimestamp ) ;
267274 }
268275
269- protected virtual void ApplyCacheHeaders ( HttpResponseMessage response , CacheTime cacheTime )
276+ protected virtual void ApplyCacheHeaders ( HttpResponseMessage response , CacheTime cacheTime , DateTimeOffset ? contentGenerationTimestamp = null )
270277 {
271278 if ( cacheTime . ClientTimeSpan > TimeSpan . Zero || MustRevalidate || Private )
272279 {
@@ -285,6 +292,10 @@ protected virtual void ApplyCacheHeaders(HttpResponseMessage response, CacheTime
285292 response . Headers . CacheControl = new CacheControlHeaderValue { NoCache = true } ;
286293 response . Headers . Add ( "Pragma" , "no-cache" ) ;
287294 }
295+ if ( ( response . Content != null ) && contentGenerationTimestamp . HasValue )
296+ {
297+ response . Content . Headers . LastModified = contentGenerationTimestamp . Value ;
298+ }
288299 }
289300
290301 protected virtual string CreateEtag ( HttpActionExecutedContext actionExecutedContext , string cachekey , CacheTime cacheTime )
0 commit comments