简体   繁体   English

如何检查是否向缓存发出请求?

[英]How can I check if a request is made to the cache?

I use a MVC application that use "outputcache" attribute:我使用使用“输出缓存”属性的 MVC 应用程序:

namespace CachingInMVC.Controllers
{
    public class HomeController : Controller
    {
        [OutputCache(Duration = 10, VaryByParam ="none", Location = 
        OutputCacheLocation.Server)]
        public ActionResult Index()
        {
            return Content(DateTime.Now.ToString("T"));
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}

How can i know/check if "index" works on cache or on server?我如何知道/检查“索引”是否适用于缓存或服务器?

You can check that in two ways:您可以通过两种方式进行检查:

  • Set a breakpoint in the action.在动作中设置断点。 And if you refresh the browser and it does not hit the breakpoint then it is being served from cache如果您刷新浏览器并且它没有命中断点,那么它是从缓存中提供的
  • Or open the web developer tool on firefox.或者打开firefox上的web开发者工具。 Under the Network section check the value in the Transferred column.Network部分下,检查Transferred列中的值。 If it says cached then it was picked from the cache如果它说缓存,那么它是从缓存中挑选出来的

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM