iT邦幫忙

1

ASP.NET MVC 快取

  • 分享至 

  • xImage

請教各位大大

目前已知

[OutputCache(Duration = 15)]
public ActionResult Index()
        {
            ...
            ViewBag.db取值 = db.Order.toline();
            ...
            return View();
        }

可以讓這個 ActionResult Index 啟用 快取 時間是15秒

請教如何要將 ActionResult Index 裡面部分程式碼片段 db取值 要快取 部分不用快取呢?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
科科
iT邦研究生 1 級 ‧ 2022-09-01 17:10:29
最佳解答

如果你是要依不同參數快取,用VaryByParam:

 [OutputCache(Duration = int.MaxValue, VaryByParam = "id")]

如果不是,而是要針對某筆資料快取在記憶體,用MemoryCache

謝謝大大的指引 已經成功使用了

科科 iT邦研究生 1 級 ‧ 2022-09-02 16:49:35 檢舉

不客氣~

我要發表回答

立即登入回答