【问题标题】:ASP.NET Outputcache when doing a ajax call and posting json执行 ajax 调用和发布 json 时的 ASP.NET Outputcache
【发布时间】:2012-03-06 17:33:24
【问题描述】:

我正在尝试在 asp.net mvc 中输出缓存一个操作方法。该方法返回json,被jquery $.ajax调用,调用中的数据为json。如何使输出缓存因发送到方法的 json 而异?

【问题讨论】:

    标签: c# asp.net-mvc json outputcache


    【解决方案1】:

    您可以使用 OutputCache 和 VaryByParam="*"

        [HttpPost]
        [OutputCache(VaryByParam="*",Duration=10)]
        public ActionResult TestOutputCache(Entry entry)
        {            
            return  Content(entry.Description + " " + DateTime.Now,"text/plain");
        }
    

    这将添加任何不同的 POST 缓冲区并单独缓存它。

    除非您知道您将拥有许多重复值,否则这不是一个好主意,因为您的缓存可能会很快变大并包含许多值。

    【讨论】:

      猜你喜欢
      • 2012-06-22
      • 1970-01-01
      • 2011-02-16
      • 1970-01-01
      • 2013-01-17
      • 2023-04-06
      • 1970-01-01
      • 2018-02-04
      • 1970-01-01
      相关资源
      最近更新 更多