System.Net.Cache.FtpRequestCacheValidator.ValidateCache C# (CSharp) Method

ValidateCache() protected method

protected ValidateCache ( ) : CacheValidationStatus
return CacheValidationStatus
        protected internal override CacheValidationStatus ValidateCache()
        {
            if (HttpProxyMode)
                return base.ValidateCache();

            if (Policy.Level >= RequestCacheLevel.Reload)
            {
                // For those policies cache is never returned
                GlobalLog.Assert("OnValidateCache()", "This validator should not be called for policy = " + Policy.ToString());
                if(Logging.On)Logging.PrintError(Logging.RequestCache, SR.GetString(SR.net_log_cache_validator_invalid_for_policy, Policy.ToString()));
                return CacheValidationStatus.DoNotTakeFromCache;
            }

            // First check is do we have a cached entry at all?
            if (CacheStream == Stream.Null || CacheEntry.IsPartialEntry)
            {
                if (Policy.Level == RequestCacheLevel.CacheOnly)
                {
                    // Throw because entry was not found and it's cache-only policy
                    FailRequest(WebExceptionStatus.CacheEntryNotFound);
                }
                if (CacheStream == Stream.Null)
                {
                    return CacheValidationStatus.DoNotTakeFromCache;
                }
                // Otherwise it's a partial entry and we can go on the wire
            }

            CacheStreamOffset = 0L;
            CacheStreamLength = CacheEntry.StreamSize;

            //
            // Before request submission validation
            //
            if (Policy.Level == RequestCacheLevel.Revalidate || CacheEntry.IsPartialEntry)
            {
                return TryConditionalRequest();
            }

            long contentOffset = Request is FtpWebRequest ? ((FtpWebRequest)Request).ContentOffset: 0L;

            if (CacheFreshnessStatus == CacheFreshnessStatus.Fresh || Policy.Level == RequestCacheLevel.CacheOnly || Policy.Level == RequestCacheLevel.CacheIfAvailable)
            {
                if (contentOffset != 0)
                {
                    if (contentOffset >= CacheStreamLength)
                    {
                        if (Policy.Level == RequestCacheLevel.CacheOnly)
                        {
                            // Throw because request is outside of cached size and it's cache-only policy
                            FailRequest(WebExceptionStatus.CacheEntryNotFound);
                        }
                        return CacheValidationStatus.DoNotTakeFromCache;
                    }
                    CacheStreamOffset = contentOffset;
                }
                return CacheValidationStatus.ReturnCachedResponse;
            }

            return CacheValidationStatus.DoNotTakeFromCache;
        }
        //