0
  [OutputCache(Duration=100)]
        public ViewDataDictionary IndexCache()
        {
            ViewDataDictionary dic = new ViewDataDictionary();

      // here I add the data to dic and MVC cached it.

            return dic;
        }
 public ActionResult Index(string param1)
        {
            var x = IndexCache();

            foreach(var y in x)
            {
                ViewData.Add(y);
            }

            return PartialView("/home/index.cshtml");
        }

这个实现是缓存视图数据的正确方法吗?

如果没有,请指导我如何获得它。

4

1 回答 1

0

阅读本教程

OutputCache属性放在返回视图数据的方法之上,例如Index,这应该缓存,无论Index返回什么,取决于属性的设置。

如果您只想缓存跨多个视图或控制器使用的数据,请在进程/内存缓存中使用System.Web.Caching

于 2013-10-28T07:21:08.023 回答