Skip to content

Instantly share code, notes, and snippets.

@trnktms
Last active November 2, 2020 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trnktms/eea964dbcb97a959a4ccaad1fe09fb22 to your computer and use it in GitHub Desktop.
Save trnktms/eea964dbcb97a959a4ccaad1fe09fb22 to your computer and use it in GitHub Desktop.
namespace Discovering.Sitecore10.Caching
{
public class OutputCacheOptions
{
public bool Enabled { get; set; }
}
[HtmlTargetElement("sitecore-output-cache")]
public class OutputCacheTagHelper : CacheTagHelper
{
public OutputCacheTagHelper(
CacheTagHelperMemoryCacheFactory factory,
HtmlEncoder htmlEncoder,
IHttpContextAccessor httpContextAccessor,
IOptions<OutputCacheOptions> cachingOptions,
IOutputCacheService outputCacheService)
: base(factory, htmlEncoder)
{
ExpiresOn = DateTimeOffset.MaxValue;
VaryBy = httpContextAccessor.HttpContext.Request.Path + "," + outputCacheService.GetLastCacheReload().ToString(CultureInfo .InvariantCulture);
Enabled = cachingOptions.Value.Enabled;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment