开发者

How to cache in Web Matrix style C# Razor project NO MVC, NO WEBFORMS

Is there a server-side wa开发者_如何学JAVAy to cache at page level in Razor c# in a matrix-style project. This is having NO MVC and no Web forms. Please only answer for plain on cshtml pages being directly interpreted.


set caching at the IIS level for the file extensions you want to cache.


Use OutputCache, which is available as an extension method available on the Response object.


Here is the answer for pure Matrix style, use the HelperResponse like so:

@{
 // check if in cache, if not get direct then set cache
 HelperResponse helperResponse = Cache["myhelper"] as HelperResponse;
 if (helperResponse == null) {
    helperResponse = myhelper();
    Cache["myhelper"] = helperResponse;
 }
 // output on page
 @helperResponse

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜