protected internal override CacheFreshnessStatus ValidateFreshness()
{
if (HttpProxyMode)
{
if (CacheStream != Stream.Null)
{
if(Logging.On)Logging.PrintInfo(Logging.RequestCache, SR.GetString(SR.net_log_cache_replacing_entry_with_HTTP_200));
// HTTP validator cannot parse FTP status code and other metadata
if (CacheEntry.EntryMetadata == null)
CacheEntry.EntryMetadata = new StringCollection();
CacheEntry.EntryMetadata.Clear();
CacheEntry.EntryMetadata.Add("HTTP/1.1 200 OK");
}
return base.ValidateFreshness();
}
DateTime nowDate = DateTime.UtcNow;
if(Logging.On)Logging.PrintInfo(Logging.RequestCache, SR.GetString(SR.net_log_cache_now_time, nowDate.ToString("r", CultureInfo.InvariantCulture)));
// If absolute Expires can be recovered
if (CacheEntry.ExpiresUtc != DateTime.MinValue)
{
//Take absolute Expires value
if(Logging.On)Logging.PrintWarning(Logging.RequestCache, SR.GetString(SR.net_log_cache_max_age_absolute, CacheEntry.ExpiresUtc.ToString("r", CultureInfo.InvariantCulture)));
if (CacheEntry.ExpiresUtc < nowDate) {
return CacheFreshnessStatus.Stale;
}
return CacheFreshnessStatus.Fresh;
}
TimeSpan age = TimeSpan.MaxValue;
if(CacheEntry.LastSynchronizedUtc != DateTime.MinValue)
{
age = nowDate - CacheEntry.LastSynchronizedUtc;
if(Logging.On)Logging.PrintInfo(Logging.RequestCache, SR.GetString(SR.net_log_cache_age1, ((int)age.TotalSeconds).ToString(NumberFormatInfo.InvariantInfo), CacheEntry.LastSynchronizedUtc.ToString("r", CultureInfo.InvariantCulture)));
}
//
// Heruistic expiration
//
if (CacheEntry.LastModifiedUtc != DateTime.MinValue)
{
TimeSpan span = (nowDate - CacheEntry.LastModifiedUtc);
int maxAgeSeconds = (int)(span.TotalSeconds/10);
if(Logging.On)Logging.PrintInfo(Logging.RequestCache, SR.GetString(SR.net_log_cache_no_max_age_use_10_percent, maxAgeSeconds.ToString(NumberFormatInfo.InvariantInfo), CacheEntry.LastModifiedUtc.ToString("r", CultureInfo.InvariantCulture)));
if (age.TotalSeconds < maxAgeSeconds) {
return CacheFreshnessStatus.Fresh;
}
return CacheFreshnessStatus.Stale;
}
// Else we can only rely on UnspecifiedMaxAge hint
if(Logging.On)Logging.PrintWarning(Logging.RequestCache, SR.GetString(SR.net_log_cache_no_max_age_use_default, ((int)(UnspecifiedMaxAge.TotalSeconds)).ToString(NumberFormatInfo.InvariantInfo)));
if (UnspecifiedMaxAge >= age)
{
return CacheFreshnessStatus.Fresh;
}
return CacheFreshnessStatus.Stale;
//return OnValidateFreshness(this);
}