Skip to content

Instantly share code, notes, and snippets.

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 ErikHen/e4afea6b4b7d0593cddfbb4c44ccfd00 to your computer and use it in GitHub Desktop.
Save ErikHen/e4afea6b4b7d0593cddfbb4c44ccfd00 to your computer and use it in GitHub Desktop.
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