@@ -155,7 +155,7 @@ private static CachedRawResponse Convert(OutputCacheEntry oce) {
155155 } ;
156156 }
157157
158- public async Task < object > Get ( string key ) {
158+ internal async Task < object > GetAsync ( string key ) {
159159 OutputCacheProviderAsync provider = GetProvider ( HttpContext . Current ) ;
160160 object result = await provider . GetAsync ( key ) ;
161161 var oce = result as OutputCacheEntry ;
@@ -170,7 +170,7 @@ public async Task<object> Get(string key) {
170170 return result ;
171171 }
172172
173- public async Task Remove ( string key , HttpContext context ) {
173+ internal async Task RemoveAsync ( string key , HttpContext context ) {
174174 // we don't know if it's in the internal cache or
175175 // one of the providers. If a context is given,
176176 // then we can narrow down to at most one provider.
@@ -189,7 +189,7 @@ public async Task Remove(string key, HttpContext context) {
189189 }
190190 }
191191
192- public async Task InsertResponse ( string cachedVaryKey ,
192+ internal async Task InsertResponseAsync ( string cachedVaryKey ,
193193 CachedVary cachedVary ,
194194 string rawResponseKey ,
195195 CachedRawResponse rawResponse ,
@@ -258,7 +258,7 @@ public async Task InsertResponse(string cachedVaryKey,
258258 }
259259 }
260260
261- public static bool IsCacheableEncoding ( string coding , string [ ] contentEncodings ) {
261+ internal static bool IsCacheableEncoding ( string coding , string [ ] contentEncodings ) {
262262 // return true if we are not varying by content encoding.
263263 if ( contentEncodings == null ) {
264264 return true ;
@@ -268,7 +268,7 @@ public static bool IsCacheableEncoding(string coding, string[] contentEncodings)
268268 // return true if the Content-Encoding header is listed
269269 }
270270
271- public static bool ContainsNonShareableCookies ( HttpResponse response ) {
271+ internal static bool ContainsNonShareableCookies ( HttpResponse response ) {
272272 HttpCookieCollection cookies = response . Cookies ;
273273 for ( int i = 0 ; i < cookies . Count ; i ++ ) {
274274 HttpCookie httpCookie = cookies [ i ] ;
@@ -279,7 +279,7 @@ public static bool ContainsNonShareableCookies(HttpResponse response) {
279279 return false ;
280280 }
281281
282- public static void UseSnapshot ( HttpRawResponse rawResponse , bool sendBody , HttpResponse response ) {
282+ internal static void UseSnapshot ( HttpRawResponse rawResponse , bool sendBody , HttpResponse response ) {
283283 if ( response . HeadersWritten )
284284 throw new HttpException ( SR . Cannot_use_snapshot_after_headers_sent ) ;
285285 response . Clear ( ) ;
@@ -296,7 +296,7 @@ public static void UseSnapshot(HttpRawResponse rawResponse, bool sendBody, HttpR
296296 response . SuppressContent = ! sendBody ;
297297 }
298298
299- public static HttpRawResponse GetSnapshot ( HttpResponse response ) {
299+ internal static HttpRawResponse GetSnapshot ( HttpResponse response ) {
300300 var headers = new NameValueCollection ( ) ;
301301 const bool hasSubstBlocks = false ;
302302 if ( response . HeadersWritten )
@@ -328,7 +328,7 @@ public static HttpRawResponse GetSnapshot(HttpResponse response) {
328328 } ;
329329 }
330330
331- public static HttpCachePolicySettings GetCurrentSettings ( HttpResponse response ) {
331+ internal static HttpCachePolicySettings GetCurrentSettings ( HttpResponse response ) {
332332 IEnumerable < KeyValuePair < HttpCacheValidateHandler , object > > validationCallbackInfo =
333333 OutputCacheUtility . GetValidationCallbacks ( response ) ;
334334
@@ -353,7 +353,7 @@ public static HttpCachePolicySettings GetCurrentSettings(HttpResponse response)
353353 } ;
354354 }
355355
356- public static void ResetFromHttpCachePolicySettings ( HttpCachePolicySettings settings ,
356+ internal static void ResetFromHttpCachePolicySettings ( HttpCachePolicySettings settings ,
357357 DateTime utcTimestampRequest , HttpResponse response ) {
358358 response . Cache . SetCacheability ( settings . Cacheability ) ;
359359 response . Cache . VaryByContentEncodings . SetContentEncodings ( settings . VaryByContentEncodings ) ;
@@ -385,13 +385,99 @@ public static void ResetFromHttpCachePolicySettings(HttpCachePolicySettings sett
385385 }
386386 }
387387
388- public static void UpdateCachedHeaders ( HttpResponse response ) {
388+ internal static void UpdateCachedHeaders ( HttpResponse response ) {
389+ //To enable Out of Band OutputCache Module support, we will always refresh the UtcTimestampRequest.
389390 if ( response . Cache . UtcTimestampCreated == DateTime . MinValue ) {
390391 response . Cache . UtcTimestampCreated = HttpContext . Current . Timestamp . ToUniversalTime ( ) ;
392+ }
393+ UpdateFromDependencies ( response ) ;
394+ }
395+
396+ private static void UpdateFromDependencies ( HttpResponse response ) {
397+ CacheDependency dep = null ;
398+ // if response.Cache.GetETag() != null && response.Cache.GetETagFromFileDependencies() == true, then this HttpCachePolicy
399+ // was created from HttpCachePolicySettings and we don't need to update _etag.
400+ if ( response . Cache . GetETag ( ) == null && response . Cache . GetETagFromFileDependencies ( ) ) {
401+ dep = OutputCacheUtility . CreateCacheDependency ( response ) ;
402+ if ( dep == null ) {
403+ return ;
404+ }
405+ string id = dep . GetUniqueID ( ) ;
406+ if ( id == null ) {
407+ throw new HttpException ( SR . No_UniqueId_Cache_Dependency ) ;
408+ }
409+ DateTime utcFileLastModifiedMax = UpdateLastModifiedTimeFromDependency ( dep , response ) ;
410+ var sb = new StringBuilder ( 256 ) ;
411+ sb . Append ( HttpRuntime . AppDomainId ) ;
412+ sb . Append ( id ) ;
413+ sb . Append ( "+LM" ) ;
414+ sb . Append ( utcFileLastModifiedMax . Ticks . ToString ( CultureInfo . InvariantCulture ) ) ;
415+ response . Cache . SetETag ( "\" " +
416+ System . Convert . ToBase64String (
417+ CryptoUtil . ComputeSha256Hash ( Encoding . UTF8 . GetBytes ( sb . ToString ( ) ) ) ) + "\" " ) ;
418+
419+
420+ if ( ! response . Cache . GetLastModifiedFromFileDependencies ( ) )
421+ return ;
422+ }
423+
424+ {
425+ if ( dep == null ) {
426+ dep = OutputCacheUtility . CreateCacheDependency ( response ) ;
427+ if ( dep == null ) {
428+ return ;
429+ }
430+ }
431+ DateTime utcFileLastModifiedMax = UpdateLastModifiedTimeFromDependency ( dep , response ) ;
432+ UtcSetLastModified ( utcFileLastModifiedMax , response ) ;
391433 }
392434 }
393435
394- public static string CreateOutputCachedItemKey (
436+ private static void UtcSetLastModified ( DateTime utcDate , HttpResponse response ) {
437+
438+ /*
439+ * Time may differ if the system time changes in the middle of the request.
440+ * Adjust the timestamp to Now if necessary.
441+ */
442+
443+ DateTime utcNow = DateTime . UtcNow ;
444+ if ( utcDate > utcNow ) {
445+ utcDate = utcNow ;
446+ }
447+
448+ /*
449+ * Because HTTP dates have a resolution of 1 second, we
450+ * need to store dates with 1 second resolution or comparisons
451+ * will be off.
452+ */
453+
454+ utcDate = new DateTime ( utcDate . Ticks - ( utcDate . Ticks % TimeSpan . TicksPerSecond ) ) ;
455+ if ( response . Cache . GetUtcLastModified ( ) != DateTime . MinValue || utcDate > response . Cache . GetUtcLastModified ( ) ) {
456+ response . Cache . SetLastModified ( utcDate ) ;
457+ }
458+
459+
460+ }
461+
462+
463+ private static DateTime UpdateLastModifiedTimeFromDependency ( CacheDependency dep , HttpResponse response ) {
464+ DateTime utcFileLastModifiedMax = dep . UtcLastModified ;
465+ if ( utcFileLastModifiedMax < response . Cache . GetUtcLastModified ( ) ) {
466+ utcFileLastModifiedMax = response . Cache . GetUtcLastModified ( ) ;
467+ }
468+ // account for difference between file system time
469+ // and DateTime.Now. On some machines it appears that
470+ // the last modified time is further in the future
471+ // that DateTime.Now
472+ DateTime utcNow = DateTime . UtcNow ;
473+ if ( utcFileLastModifiedMax > utcNow ) {
474+ utcFileLastModifiedMax = utcNow ;
475+ }
476+ return utcFileLastModifiedMax ;
477+
478+ }
479+
480+ private static string CreateOutputCachedItemKey (
395481 string path ,
396482 string verb ,
397483 HttpContext context ,
@@ -530,7 +616,7 @@ public static string CreateOutputCachedItemKey(
530616 * and form posted data.
531617 */
532618
533- public static string CreateOutputCachedItemKeyAsync ( HttpContext context , CachedVary cachedVary ) {
619+ internal static string CreateOutputCachedItemKey ( HttpContext context , CachedVary cachedVary ) {
534620 return CreateOutputCachedItemKey ( context . Request . Path , context . Request . HttpMethod , context , cachedVary ) ;
535621 }
536622
@@ -540,7 +626,7 @@ public static string CreateOutputCachedItemKeyAsync(HttpContext context, CachedV
540626 * returns either i) an acceptable index in contentEncodings, ii) -1 if the identity is acceptable, or iii) -2 if nothing is acceptable
541627 */
542628
543- public static int GetAcceptableEncoding ( string [ ] contentEncodings , int startIndex , string acceptEncoding ) {
629+ internal static int GetAcceptableEncoding ( string [ ] contentEncodings , int startIndex , string acceptEncoding ) {
544630 // The format of Accept-Encoding is ( 1#( codings [ ";" "q" "=" qvalue ] ) | "*" )
545631 if ( string . IsNullOrEmpty ( acceptEncoding ) ) {
546632 return - 1 ; // use "identity"
@@ -604,9 +690,9 @@ public static int GetAcceptableEncoding(string[] contentEncodings, int startInde
604690 return bestCodingIndex ; // coding index with highest weight, possibly -1 or -2
605691 }
606692
607- public static double Tolerance { get ; set ; }
693+ private static double Tolerance { get ; set ; }
608694
609- // Get the weight of the specified coding from the Accept-Encoding header.
695+ // GetAsync the weight of the specified coding from the Accept-Encoding header.
610696 // 1 means use this coding. 0 means don't use this coding. A number between
611697 // 1 and 0 must be compared with other codings. -1 means the coding was not found
612698 private static double GetAcceptableEncodingHelper ( string coding , string acceptEncoding ) {
@@ -689,7 +775,7 @@ private static bool IsIdentityAcceptable(string acceptEncoding) {
689775 return result ;
690776 }
691777
692- public static bool IsAcceptableEncoding ( string contentEncoding , string acceptEncoding ) {
778+ internal static bool IsAcceptableEncoding ( string contentEncoding , string acceptEncoding ) {
693779 if ( string . IsNullOrEmpty ( contentEncoding ) ) {
694780 // if Content-Encoding is not set treat it as the identity
695781 contentEncoding = Identity ;
@@ -703,5 +789,7 @@ public static bool IsAcceptableEncoding(string contentEncoding, string acceptEnc
703789 return ! ( Math . Abs ( weight ) < tolerance ) &&
704790 ( ! ( weight <= 0 ) || Math . Abs ( GetAcceptableEncodingHelper ( Asterisk , acceptEncoding ) ) > 0 ) ;
705791 }
792+
793+
706794 }
707795}
0 commit comments