Want to know about - what is different between HttpContext.Response.Cache and HttpContext.Current.Cache ? and what should be used in an ASP.NET MVC web application?
Why am I asking this question?
Since I have my own [NoCache] attribute, which is responsible for [NoCache] cache during view redirection.
eg.
public override void OnActionExecuting(ActionExecutingContext filterContext) { var cache = filterContext.HttpContext.Response.Cache; cache.SetExpires(DateTime.Now.AddDays(-1)); cache.SetValidUntilExpires(false); cache.SetRevalidation(HttpCacheRevalidation.AllCaches); cache.SetCacheability(HttpCacheability.NoCache); cache.SetNoStore(); base.OnActionExecuting(filterContext); }
And I use this attribute above in my BaseController , for example ..
[NoCache] public class BaseController : Controller { }
It works great!
BUT, in terms of authentication - I store some information in the cache below the mechanism
public ActionResult Login() { HttpContext.Current.Cache.Insert("someKey", "someValue", null, expiredTime.Value, Cache.NoSlidingExpiration); return view(); }
SO, my question is:
I use my own attribute in the base class of the controller, which is responsible for clearing cache elements, although I can still access the key and cache value in the entire application that was set by the login method code.
Why do both cache mechanisms act differently? What is the difference between the two?
Could you offer some idea or information about this.
source share