【问题标题】:Can ASP.NET outputCacheProfiles be used with Response.Cache?ASP.NET outputCacheProfiles 可以与 Response.Cache 一起使用吗?
【发布时间】:2010-11-26 09:26:53
【问题描述】:

使用@OutputCache 指令时,您可以在web.config 中定义缓存配置文件如下:

<system.web>
  <caching>
    <outputCacheSettings>
      <outputCacheProfiles>
        <add name="myprofile" duration="30" enabled="true" varyByParam="myfield"/>
      </outputCacheProfiles>
    </outputCacheSettings>
  </caching>
</system.web>

但是,在我的应用中,我有一些页面需要使用程序化缓存而不是声明性的,例如:

Response.Cache.SetExpires(DateTime.Now.AddSeconds(5));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetValidUntilExpires(true);

是否可以使用 Response.Cache 并利用 outputCacheProfiles? 例如,

Response.Cache.ApplyCacheProfile("myprofile");

【问题讨论】:

    标签: .net asp.net caching outputcache


    【解决方案1】:

    缓存属性被称为位置,所以你不需要以编程方式设置它,至于其他为什么不试试看呢?

    【讨论】:

    • 我对 ApplyCacheProfile() 的调用只是伪代码。该方法不存在。我在问这样的方法是否存在。
    【解决方案2】:

    在 MVC 中,您可以在控制器上使用属性 [OutputCache(CacheProfile = "myprofile")]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-15
      相关资源
      最近更新 更多