Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
namespace AlloyDemo.Business
{
public sealed class EditableContentOutputCacheAttribute : ContentOutputCacheAttribute
{
public EditableContentOutputCacheAttribute()
{
UseOutputCacheValidator = UseOutputCache;
}
private static bool UseOutputCache(IPrincipal principal, HttpContextBase context, TimeSpan duration)
{
var useCache = false;
if (!principal.Identity.IsAuthenticated && duration != TimeSpan.Zero)
{
if (string.Equals(context.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
{
useCache = true;
var url = context.Request.Url?.ToString();
var content = UrlResolver.Current.Route(new UrlBuilder(url));
if (content is IDisableOutputCache page)
{
useCache = page.DisableOutputCache != true;
}
}
}
return useCache;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.