将缓存数据条目的时间戳重置为 now()

我正在尝试重置缓存条目的时间戳。我想知道如何实现这一目标。


现在我正在创建一个新实例 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 以从头开始计数。


白猪掌柜的
浏览 76回答 1
1回答

噜噜哒

SetSlidingExpiration(TimeSpan.FromSeconds(20))每次访问缓存中的项目时都会自动重置缓存时间戳 public object GetFile(string key)  {             return (_memoryCache.Get(Cache(key));  }因此,如果像这样访问缓存条目,resultFromCache = _cacheServiceClass.GetFile(cacheKey);则 MemoryCacheEntryOptions() SetSlidingExpiration(TimeSpan.FromSeconds(20))每次都会重置。
打开App,查看更多内容
随时随地看视频慕课网APP