Created
May 1, 2019 14:12
-
-
Save ErikHen/e4afea6b4b7d0593cddfbb4c44ccfd00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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