Here’s what I did after I was finished shaking my fists at the sky during a torrential downpour.
I began to question the most basic of my nerdly assumptions. Do I have the right connection string? Should I even be using SQL anymore? Is the fabric of the universe collapsing?
After a therapeutic session of pacing and taking in some Carl Sagan to re-staple my faith in the sturdiness of the cosmos, it dawned on me that this particular service call was in fact an HTTP request made from a browser. And yes, the damned thing was caching.
To remedy any further zombie data tomfoolery, I have here a NoCacheAttribute class that inherits from ActionFilterAttribute:
public class NoCacheAttribute : ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
var cache = filterContext.HttpContext.Response.Cache;
cache.SetExpires(DateTime.UtcNow.AddDays(-1));
cache.SetValidUntilExpires(false);
cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
cache.SetCacheability(HttpCacheability.NoCache);
cache.SetNoStore();
base.OnResultExecuting(filterContext);
}
}This meek mod merely intercepts the result, grabs ahold of the HttpResponse’s cache settings and beats them soundly about the head and shoulders until they are certain that they’re not going to cache anything that comes from this response. Like, ever.
Here’s How To Make Sure You’re Not Returning Zombies From An MVC Action [ Aptera Software ]

