亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將緩存數據條目的時間戳重置為 now()

將緩存數據條目的時間戳重置為 now()

C#
白豬掌柜的 2022-12-31 13:57:20
我正在嘗試重置緩存條目的時間戳。我想知道如何實現這一目標?,F在我正在創建一個新實例 MemoryCacheEntryOptions        private MemoryCacheEntryOptions GetCacheOptions()        {            return new MemoryCacheEntryOptions()                .SetSlidingExpiration(TimeSpan.FromSeconds(20)); // Cache for some seconds.        }  每次SetSlideExpiration()緩存數據出現在MemoryCacheEntry.因此,如果public bool hasCached(string key, byte[] values){  return _memoryCache.TryGetValue(GetDocStoreKey(key), out values);}返回true我應該能夠重置 SetSlideExpiration 以從頭開始計數。
查看完整描述

1 回答

?
嚕嚕噠

TA貢獻1784條經驗 獲得超7個贊

SetSlidingExpiration(TimeSpan.FromSeconds(20))每次訪問緩存中的項目時都會自動重置緩存時間戳

 public object GetFile(string key)
 {  
          return (_memoryCache.Get(Cache(key));
 }

因此,如果像這樣訪問緩存條目,resultFromCache = _cacheServiceClass.GetFile(cacheKey);則 MemoryCacheEntryOptions() SetSlidingExpiration(TimeSpan.FromSeconds(20))每次都會重置。


查看完整回答
反對 回復 2022-12-31
  • 1 回答
  • 0 關注
  • 70 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號