System.Net.Cache.Rfc2616.OnValidateCache C# (CSharp) Method

OnValidateCache() public static method

public static OnValidateCache ( HttpRequestCacheValidator ctx ) : CacheValidationStatus
ctx HttpRequestCacheValidator
return CacheValidationStatus
        public static CacheValidationStatus OnValidateCache(HttpRequestCacheValidator ctx)
        {

            if (Common.ValidateCacheByVaryHeader(ctx) == TriState.Invalid) {
                // RFC 2616 is tricky on this. In theory we could make a conditional request.
                // However we rather will not.
                // And the reason can be deducted from the RFC definitoin of the response Vary Header.
                return CacheValidationStatus.DoNotTakeFromCache;
            }


            // For Revalidate option we perform a wire request anyway
            if (ctx.Policy.Level == HttpRequestCacheLevel.Revalidate) {
                return Common.TryConditionalRequest(ctx);
            }

            if (Common.ValidateCacheBySpecialCases(ctx) == TriState.Invalid)
            {
                // This takes over the cache policy since the cache content may be sematically incorrect
                if (ctx.Policy.Level == HttpRequestCacheLevel.CacheOnly) {
                    // Cannot do a wire request
                    return CacheValidationStatus.DoNotTakeFromCache;
                }
                return Common.TryConditionalRequest(ctx);
            }


            bool enoughFresh = Common.ValidateCacheByClientPolicy(ctx);

            if (enoughFresh || ctx.Policy.Level == HttpRequestCacheLevel.CacheOnly || ctx.Policy.Level == HttpRequestCacheLevel.CacheIfAvailable || ctx.Policy.Level == HttpRequestCacheLevel.CacheOrNextCacheOnly)
            {
                // The freshness does not matter, check does user requested Range fits into cached entry
                CacheValidationStatus result = Common.TryResponseFromCache(ctx);

                if (result != CacheValidationStatus.ReturnCachedResponse) {
                    if (ctx.Policy.Level == HttpRequestCacheLevel.CacheOnly) {
                        // Cannot do a wire request
                        return CacheValidationStatus.DoNotTakeFromCache;
                    }
                    return result;
                }

                if(Logging.On)Logging.PrintInfo(Logging.RequestCache, SR.GetString(SR.net_log_cache_valid_as_fresh_or_because_policy, ctx.Policy.ToString()));
                return CacheValidationStatus.ReturnCachedResponse;
            }
            // This will return either Continue=conditional request or DoNotTakeFromCache==Unconditional request
            return Common.TryConditionalRequest(ctx);
        }