【问题标题】:How do I cache a composite server control?如何缓存复合服务器控件?
【发布时间】:2011-03-28 23:34:32
【问题描述】:

如何使用系统缓存对象 HttpContext.Current.Cache 在缓存中存储自定义服务器控件?

目前我的代码如下所示:

            string adxkey = string.Format("adxdependency:document:{0}", this.SearchRootDocumentKey);
        System.Web.Caching.CacheDependency cd = new System.Web.Caching.CacheDependency(null, new string[] { adxkey });
        HttpContext.Current.Cache.Insert(adxkey, this, cd);   

这位于 OnInit 方法中。我的问题是:

  • 有没有更好的方法来放置缓存代码?
  • 您能否像上面那样通过传递对服务器控件的引用来缓存服务器控件?还是我需要缓存渲染的 html?

非常感谢您提供如何以编程方式缓存服务器控件的示例!谢谢。

【问题讨论】:

    标签: .net caching servercontrols composite-controls cache-dependency


    【解决方案1】:

    对此的简短回答是,您需要将缓存属性添加到页面或用户控件,而不是服务器控件。我已经写了一篇关于如何做到这一点的博客文章,你可以在这里找到它:

    http://www.dirigodev.com/blog/post/AspNET-Caching-101-Part-2-Cache-Key-Dependencies.aspx

    【讨论】:

      猜你喜欢
      • 2011-04-13
      • 2011-05-30
      • 1970-01-01
      • 2021-08-07
      • 2015-04-08
      • 1970-01-01
      • 2013-05-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多