protected internal override CacheValidationStatus RevalidateCache()
{
if (HttpProxyMode)
return base.RevalidateCache();
if (Policy.Level >= RequestCacheLevel.Reload)
{
// For those policies cache is never returned
GlobalLog.Assert("RevalidateCache()", "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 still hold on a cached entry?
if (CacheStream == Stream.Null)
{
return CacheValidationStatus.DoNotTakeFromCache;
}
//
// This is a second+ time validation after receiving at least one response
//
CacheValidationStatus result = CacheValidationStatus.DoNotTakeFromCache;
FtpWebResponse resp = Response as FtpWebResponse;
if (resp == null)
{
// This will result to an application error
return CacheValidationStatus.DoNotTakeFromCache;
}
if (resp.StatusCode == FtpStatusCode.FileStatus)
{
if(Logging.On) Logging.PrintInfo(Logging.RequestCache, SR.GetString(SR.net_log_cache_response_last_modified, resp.LastModified.ToUniversalTime().ToString("r", CultureInfo.InvariantCulture), resp.ContentLength));
if(Logging.On) Logging.PrintInfo(Logging.RequestCache, SR.GetString(SR.net_log_cache_cache_last_modified, CacheEntry.LastModifiedUtc.ToString("r", CultureInfo.InvariantCulture), CacheEntry.StreamSize));
if (CacheStreamOffset != 0L && CacheEntry.IsPartialEntry)
{
//should never happen
if(Logging.On) Logging.PrintError(Logging.RequestCache, SR.GetString(SR.net_log_cache_partial_and_non_zero_content_offset, CacheStreamOffset.ToString(CultureInfo.InvariantCulture)));
result = CacheValidationStatus.DoNotTakeFromCache;
}
if (resp.LastModified.ToUniversalTime() == CacheEntry.LastModifiedUtc)
{
if (CacheEntry.IsPartialEntry)
{
// A caller will need to use Validator.CacheEntry.StreamSize to figure out what the restart point is
if (resp.ContentLength > 0)
this.CacheStreamLength = resp.ContentLength;
else
this.CacheStreamLength = -1;
result = CacheValidationStatus.CombineCachedAndServerResponse;
}
else if (resp.ContentLength == CacheEntry.StreamSize)
{
result = CacheValidationStatus.ReturnCachedResponse;
}
else
result = CacheValidationStatus.DoNotTakeFromCache;
}
else
result = CacheValidationStatus.DoNotTakeFromCache;
}
else
{
result = CacheValidationStatus.DoNotTakeFromCache;
}
return result;
}