Using System; using System. collections. generic; using System. IO. compression; using System. linq; using System. web; using System. web. mvc; using System. web. UI; namespace MvcAppCache. controllers {/*** FireFox: Can I enter about: cache in the browser? Device = disk: view the browser Cache data. ** 1. Add ** Response. Cache. SetOmitVaryStar (true) to the Action. * This prevents unstable Cache. 200 and 304 may occur occasionally. * By: Rhythmk.cnblogs.com <Wang Kun> */public class HomeController: Controller {// GET:/Home/[OutputCache (Duration = 30, Location = OutputCacheLocation. serverAndClient)] public ActionResult Index () {Response. cache. setOmitVaryStar (true); ViewBag. time = DateTime. now; return View ();} /// <summary> /// server cache 30 S /// </summary> /// <returns> </returns> [OutputCache (Duration = 30, Location = OutputCacheLoc Ation. serverAndClient)] public ActionResult ServerCache () {Response. cache. setOmitVaryStar (true); ViewBag. time = DateTime. now; return View ();} /** configure the cache time through the configuration file <caching> <outputCacheSettings> <outputCacheProfiles> <add name = "Cache1Hour" duration = "60" varyByParam = "none"/> </outputCacheProfiles> </outputCacheSettings> </caching> *: rhythmk.cnblogs.com <Wang Kun> */[OutputCache (CacheProfile = "Cache1 Hour ", Location = OutputCacheLocation. client)] public ActionResult ConfigCache () {Response. cache. setOmitVaryStar (true); ViewBag. time = DateTime. now; return View () ;}[ CompressFilter] public ActionResult Compress () {return View ();} public ActionResult NoCompress () {return PartialView ("Compress ");}} /// <summary> /// output compression /// </summary> [AttributeUsage (AttributeTargets. class | AttributeTargets. M Ethod)] public class CompressFilter: ActionFilterAttribute {public override void OnActionExecuting (ActionExecutingContext filterContext) {/* OnActionExecuting in the ActionFilterAttribute class, nothing is actually just a blank virtual method. Base. onActionExecuting (filterContext); * By: Rhythmk.cnblogs.com <Wang Kun> */HttpRequestBase request = filterContext. httpContext. request; string acceptEncoding = request. headers ["Accept-Encoding"]; if (string. isNullOrEmpty (acceptEncoding) return; acceptEncoding = acceptEncoding. toUpperInvariant (); HttpResponseBase response = filterContext. httpContext. response; if (acceptEncoding. contains ("GZIP") {response. appendHeader ("Content-encoding", "gzip"); response. filter = new GZipStream (response. filter, CompressionMode. compress);} else if (acceptEncoding. contains ("DEFLATE") {response. appendHeader ("Content-encoding", "deflate"); response. filter = new DeflateStream (response. filter, CompressionMode. compress );}}}}