public async Task CacheExtension_SetAndGetMethods_ReturnActualValuesCorrectly() { // ARRANGE var key = "Employee25"; await _cacheThatsConnected.SetAsync(key, new Employee(25, "Clayton Gragg")); // ACT var value = await _cacheThatsConnected.GetAsync <Employee>(key); // should return null, as the connection bool deletionResult = await _cacheThatsConnected.DeleteAsync(key); Assert.That(value.Id, Is.EqualTo(25)); Assert.IsTrue(deletionResult); }
public async Task <ActionResult> News(bool?refresh) { var blob = _blobService.GetBlobReference("content", NewsBlobNameHtml); var html = await _cacheAccessor.GetAsync <string>(NewsBlobNameHtml); var etag = await _cacheAccessor.GetAsync <string>(NewsBlobETag); if (refresh.GetValueOrDefault()) { await _cacheAccessor.DeleteAsync(ArchiveBlobNameHtml); } if ((html == null && await blob.ExistsAsync()) || refresh.GetValueOrDefault()) { await blob.FetchAttributesAsync(); html = await blob.DownloadTextAsync(); etag = CleanETag(blob.Properties.ETag); await _cacheAccessor.SetAsync(NewsBlobNameHtml, html, TimeSpan.FromHours(1)); await _cacheAccessor.SetAsync(NewsBlobETag, etag, TimeSpan.FromHours(1)); } Response.Cookies.Set(new HttpCookie(NewsBlobETag, etag) { Expires = DateTime.MaxValue, SameSite = SameSiteMode.Strict }); return(View(new MvcHtmlString(html))); }
private async Task <bool> CleanSitemapCache() { await _cacheAccessor.DeleteAsync($"{_cacheTag}_index"); await _cacheAccessor.DeleteAsync($"{_cacheTag}_site"); foreach (var est in await GetEstablishmentTypes()) { await _cacheAccessor.DeleteAsync($"{_cacheTag}_est_{est}"); } foreach (var grp in await GetGroupTypes()) { await _cacheAccessor.DeleteAsync($"{_cacheTag}_group_{grp}"); } return(true); }