我正在嘗試重置緩存條目的時間戳。我想知道如何實現這一目標?,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))
每次都會重置。
- 1 回答
- 0 關注
- 70 瀏覽
添加回答
舉報
0/150
提交
取消