IMemoryCache Remove All
[删除(380066935@qq.com或微信通知)]
private readonly MemoryCacheEntryOptions _cacheOptions;
private readonly ILogger<ClientImageCacheService> _logger;
private readonly IMemoryCache _memoryCache;
public ClientImageCacheService(RestClient client, IMemoryCache cache, NotificationsService notifications,
ILogger<ClientImageCacheService> logger)
{
_logger = logger;
_memoryCache = cache;
_cacheOptions = new MemoryCacheEntryOptions()
.SetSize(1)
.SetSlidingExpiration(TimeSpan.FromHours(4));
_notifications.SubscribeToNotification<string>(NotificationType.CacheEvict, Evict);
}
public Task ClearCache()
{
var memCache = _memoryCache as MemoryCache;
if (memCache is not null)
{
// Force the cache to compact 100% of the memory
memCache.Compact(1.0);
}
return Task.CompletedTask;
}