我正在尝试重置缓存条目上的时间戳。我想知道如何实现这一目标。
现在我正在创建一个新的MemoryCacheEntryOptions
实例
private MemoryCacheEntryOptions GetCacheOptions()
{
return new MemoryCacheEntryOptions()
.SetSlidingExpiration(TimeSpan.FromSeconds(20)); // Cache for some seconds.
}
我希望能够重置SetSlideExpiration()
以从零(0)秒开始计数,每次MemoryCacheEntry
中存在缓存数据。
因此,如果
public bool hasCached(string key, byte[] values)
{
return _memoryCache.TryGetValue(GetDocStoreKey(key), out values);
}
返回true
我应该能够重置SetSlideExpiration从头开始计数。
每次访问缓存中的项目时,SetSlidingExpiration(TimeSpan.FromSeconds(20))
都会自动重置缓存时间戳
public object GetFile(string key)
{
return (_memoryCache.Get(Cache(key));
}
因此,如果缓存条目是像这样的resultFromCache = _cacheServiceClass.GetFile(cacheKey);
访问,则MemoryCacheEntryOptions()将每次重置SetSlidingExpiration(TimeSpan.FromSeconds(20))
。