Skip to content

Instantly share code, notes, and snippets.

@fxbeckers
Created July 17, 2013 15:38
Show Gist options
  • Save fxbeckers/6021734 to your computer and use it in GitHub Desktop.
Save fxbeckers/6021734 to your computer and use it in GitHub Desktop.
No Cache Attribute
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public sealed class NoCacheAttribute : ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
filterContext.HttpContext.Response.Cache.SetNoStore();
base.OnResultExecuting(filterContext);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment