The above are fine if you know what pages you want to clear the cache for. In my instance (ASP.NET MVC) I referenced the same data from all over. Therefore, when I did a [save] I wanted to clear cache site wide. This is what worked for me: http://aspalliance.com/668
Acest lucru se face în contextul unui filtru OnActionExecuting. S-ar putea realiza la fel de usor cu ajutorul sistemului OnActionExecuting intr-un BaseController sau ceva de genul acesta.
HttpContextBase httpContext = filterContext.HttpContext;
httpContext.Response.AddCacheItemDependency("Pages");
Înființat:
protected void Application_Start()
{
HttpRuntime.Cache.Insert("Pages", DateTime.Now);
}
Minor Tweak:
Am un ajutor care adaugă "mesaje flash" (Mesaje de eroare, mesaje de succes - "Acest articol a fost salvat cu succes", etc). Pentru a evita ca mesajul flash să apară la fiecare GET ulterior, a trebuit să invalid după scrierea mesajului flash.
Ștergerea memoriei cache:
HttpRuntime.Cache.Insert("Pages", DateTime.Now);
Sper că acest lucru vă ajută.