public void HashCodeNotEqualsTest() { var item = new CacheItem <string>("test category", "test id", "test item", DateTime.Now); var item2 = new CacheItem <string>("test category 2", "test id 2", "test item 2", DateTime.Now); Assert.NotEqual(item.GetHashCode(), item2.GetHashCode()); }
public void HashCodeEqualsTest() { var date = DateTime.Now; var item = new CacheItem <string>("test category", "test id", "test item", date); var item2 = new CacheItem <string>("test category", "test id", "test item", date); Assert.Equal(item.GetHashCode(), item2.GetHashCode()); }
/// <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); } // 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)); } } response.Cache.SetOmitVaryStar(true); if (_varyQueryStringParameters != null) { foreach (var queryStringParam in _varyQueryStringParameters) { response.Cache.VaryByParams[queryStringParam] = true; } } foreach (var varyRequestHeader in _varyRequestHeaders) { response.Cache.VaryByHeaders[varyRequestHeader] = true; } // create a unique cache per browser, in case a Theme is rendered differently (e.g., mobile) // c.f. http://msdn.microsoft.com/en-us/library/aa478965.aspx // c.f. http://stackoverflow.com/questions/6007287/outputcache-varybyheader-user-agent-or-varybycustom-browser response.Cache.SetVaryByCustom("browser"); // enabling this would create an entry for each different browser sub-version // response.Cache.VaryByHeaders.UserAgent = true; }
/// <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; } }