Batman.MVC.ActionFilters.ClientSideCache.OnActionExecuting C# (CSharp) Method

OnActionExecuting() public method

Action executing
public OnActionExecuting ( System.Web.Mvc.ActionExecutingContext filterContext ) : void
filterContext System.Web.Mvc.ActionExecutingContext Filter context
return void
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            HttpContextBase Context = filterContext.HttpContext;
            Context.Response.Cache.VaryByHeaders["Accept-Encoding"] = true;
            DateTime Date = GetDateLastModified(Context);
            string Etag = GetETag(Context);
            string IncomingEtag = Context.Request.Headers["If-None-Match"];
            string ModifiedSince = Context.Request.Headers["If-Modified-Since"];
            DateTime ModifiedSinceDate = DateTime.Now;
            DateTime.TryParse(ModifiedSince, out ModifiedSinceDate);

            Date = DateTime.Parse(Date.ToString("r"));

            Context.Response.Cache.SetLastModified(Date);
            Context.Response.Cache.SetExpires(DateTime.Now.ToUniversalTime().AddDays(DaysToCache));
            Context.Response.Cache.SetCacheability(HttpCacheability.Public);
            Context.Response.Cache.SetMaxAge(new TimeSpan(DaysToCache, 0, 0, 0));
            Context.Response.Cache.SetRevalidation(HttpCacheRevalidation.None);
            Context.Response.Cache.SetETag(Etag);
            if (string.Compare(IncomingEtag, Etag, StringComparison.Ordinal) == 0
                || Date.CompareTo(ModifiedSinceDate) <= 0)
            {
                Context.Response.StatusCode = (int)HttpStatusCode.NotModified;
                Context.ApplicationInstance.CompleteRequest();
                return;
            }
            base.OnActionExecuting(filterContext);
        }