日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

Mvc 页面缓存 OutputCache VaryByCustom

發布時間:2024/1/17 c/c++ 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Mvc 页面缓存 OutputCache VaryByCustom 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

優化網站,dotNet MVC 可以通過(OutputCache)特性在某些Action上使用緩存,如果我們想要自定義緩存依據可以通過如下方式進行:

第一步, 在 global.asax.cs 文件中 overite GetVaryByCustomString函數:

/// <summary>/// 自定義生成的依據/// </summary>/// <param name="context"></param>/// <param name="custom"></param>/// <returns></returns>public override string GetVaryByCustomString(HttpContext context, string custom) {if (EqualsIgnoreCase("AnonymousID", custom)) {return context.Request.AnonymousID;}return base.GetVaryByCustomString(context, custom);}// System.Web.Util.StringUtilstatic bool EqualsIgnoreCase(string s1, string s2) {return (string.IsNullOrEmpty(s1) && string.IsNullOrEmpty(s2)) ||(!string.IsNullOrEmpty(s1) && !string.IsNullOrEmpty(s2) && s2.Length == s1.Length &&string.Compare(s1, 0, s2, 0, s2.Length, StringComparison.OrdinalIgnoreCase) == 0);}

第二步:在需要輸出緩存的Action上添加OutPutCache特性:

[OutputCache(CacheProfile = "StaticPage")]public ActionResult Index(){return View();}

第三部:為了便于修改緩存配置,我們可以辦具體的緩存設置寫在配置文件中,如下:

<caching><outputcachesettings> <outputcacheprofiles><clear /><!-- 24 hours--><add varybycustom="AnonymousID" varybyparam="*" duration="86400" name="StaticPage" /></outputcacheprofiles></outputcachesettings></caching>

轉載于:https://www.cnblogs.com/lcxmvc/p/4628842.html

總結

以上是生活随笔為你收集整理的Mvc 页面缓存 OutputCache VaryByCustom的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。