3

我正在开发一个使用 ServiceStack 作为 API 提供程序的单页应用程序 (SPA),有两个可用的 cshtml 页面,index.cshtml 和 admin.cshtml。这些文件是 cshtml 而不是简单的 html 的唯一原因是利用了 Asp.Net System.Web.Optimization。

考虑到我没有可用的控制器,我试图弄清楚如何启用输出缓存。我知道如果我有控制器,我会使用 OutputCacheAttribute。

我也明白应用程序需要重构,但由于时间关系,我需要让它在当前结构中工作。任何帮助将不胜感激。

PS 我也试图避免覆盖输出标题,因为我不想自己管理 ETag。

4

1 回答 1

3

您可以使用 Response.OutputCache() 扩展方法:

@{
    Response.OutputCache(30);
 }

它有很多参数,允许您指定与在 OutputCache 属性中相同的内容。

这是文档:

public static void 
OutputCache
(this System.Web.HttpResponseBase response,
int numberOfSeconds, [bool sliding = false], 
System.Collections.Generic.IEnumerable<string> varyByParams = null], 
[System.Collections.Generic.IEnumerable<string> varyByHeaders = null], 
[System.Collections.Generic.IEnumerable<string> varyByContentEncodings = null], 
[System.Web.HttpCacheability cacheability = System.Web.HttpCacheability.Public])
于 2013-07-22T22:18:14.327 回答