public Task DisplayingFinalizedAsync(ShapeDisplayContext context) { var cacheContext = context.ShapeMetadata.Cache(); if (cacheContext != null && _openScopes.ContainsKey(cacheContext.CacheId)) { _cacheScopeManager.ExitScope(); _openScopes.Remove(cacheContext.CacheId); } return(Task.CompletedTask); }
/// <inheritdoc /> public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } IHtmlContent content; if (Enabled) { var cacheContext = new CacheContext(CacheId); if (!String.IsNullOrEmpty(VaryBy)) { cacheContext.AddContext(VaryBy.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries)); } if (!String.IsNullOrEmpty(Dependencies)) { cacheContext.AddTag(Dependencies.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries)); } var hasEvictionCriteria = false; if (ExpiresOn.HasValue) { hasEvictionCriteria = true; cacheContext.WithExpiryOn(ExpiresOn.Value); } if (ExpiresAfter.HasValue) { hasEvictionCriteria = true; cacheContext.WithExpiryAfter(ExpiresAfter.Value); } if (ExpiresSliding.HasValue) { hasEvictionCriteria = true; cacheContext.WithExpirySliding(ExpiresSliding.Value); } if (!hasEvictionCriteria) { cacheContext.WithExpirySliding(DefaultExpiration); } _cacheScopeManager.EnterScope(cacheContext); try { content = await output.GetChildContentAsync(); } finally { _cacheScopeManager.ExitScope(); } content = await ProcessContentAsync(output, cacheContext); } else { content = await output.GetChildContentAsync(); } // Clear the contents of the "cache" element since we don't want to render it. output.SuppressOutput(); output.Content.SetHtmlContent(content); }