【问题标题】:How can I check if a request is made to the cache?如何检查是否向缓存发出请求?
【发布时间】:2022-01-06 08:48:21
【问题描述】:

我使用一个使用“outputcache”属性的 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();
        }
    }
}

我如何知道/检查“索引”是否适用于缓存或服务器?

【问题讨论】:

    标签: c# asp.net asp.net-mvc caching


    【解决方案1】:

    您可以通过两种方式进行检查:

    • 在操作中设置断点。如果您刷新浏览器并且它没有命中断点,那么它是从缓存中提供服务的
    • 或在 Firefox 上打开 Web 开发人员工具。在 Network 部分检查 Transferred 列中的值。如果它说 cached 那么它是从缓存中挑选出来的

    【讨论】:

      猜你喜欢
      • 2011-08-31
      • 2017-11-05
      • 2017-09-02
      • 2010-12-09
      • 2015-05-28
      • 2012-09-22
      • 2011-05-17
      • 2019-11-18
      相关资源
      最近更新 更多