/// <summary> /// Define valid cache control values /// </summary> private void ApplyCacheControl(CacheItem cacheItem, HttpResponseBase response) { if (_maxAge > 0) { var maxAge = new TimeSpan(0, 0, 0, _maxAge); //cacheItem.ValidUntilUtc - _clock.UtcNow; if (maxAge.TotalMilliseconds < 0) { maxAge = TimeSpan.FromSeconds(0); } response.Cache.SetCacheability(HttpCacheability.Public); response.Cache.SetMaxAge(maxAge); } response.Cache.VaryByParams["*"] = true; response.DisableUserCache(); // keeping this examples for later usage // response.DisableKernelCache(); // response.Cache.SetOmitVaryStar(true); // an ETag is a string that uniquely identifies a specific version of a component. // we use the cache item to detect if it's a new one if (HttpRuntime.UsingIntegratedPipeline) { if (response.Headers.Get("ETag") == null) { response.Cache.SetETag(cacheItem.GetHashCode().ToString(CultureInfo.InvariantCulture)); } } if (_varyQueryStringParameters != null) { foreach (var queryStringParam in _varyQueryStringParameters) { response.Cache.VaryByParams[queryStringParam] = true; } } foreach (var varyRequestHeader in _varyRequestHeaders) { response.Cache.VaryByHeaders[varyRequestHeader] = true; } }
public override void DisableUserCache() { _response.DisableUserCache(); }