public void Register(ICacheStack cacheStack) { if (IsRegistered) { throw new InvalidOperationException($"{nameof(RedisRemoteEvictionExtension)} can only be registered to one {nameof(ICacheStack)}"); } IsRegistered = true; Subscriber.Subscribe(RedisChannel) .OnMessage(async(channelMessage) => { string cacheKey = channelMessage.Message; var shouldEvictLocally = false; lock (FlaggedRefreshesLockObj) { shouldEvictLocally = FlaggedRefreshes.Remove(cacheKey) == false; } if (shouldEvictLocally) { for (var i = 0; i < EvictFromLayers.Length; i++) { await EvictFromLayers[i].EvictAsync(cacheKey); } } }); }
public void Register(ICacheStack cacheStack) { foreach (var extension in AllExtensions) { extension.Register(cacheStack); } }
public void Register(ICacheStack cacheStack) { if (BackgroundTask != null) { throw new InvalidOperationException($"{nameof(AutoCleanupExtension)} can only be registered to one {nameof(ICacheStack)}"); } BackgroundTask = BackgroundCleanup(cacheStack); }
public void Register(ICacheStack cacheStack) { if (RegisteredStack != null) { throw new InvalidOperationException($"{nameof(RedisLockExtension)} can only be registered to one {nameof(ICacheStack)}"); } RegisteredStack = cacheStack; }
public LocalGetBenchmark() { _concurrentDictionary = CreateConcurrentDictionary(); _modernCache = CreateModernCache(); _cacheTower = CreateCacheTower(); _foundatio = CreateFoundatio(); _lazyCache = CreateLazyCache(); _fusionCache = CreateFusionCache(); _easyCache = CreateEasyCache(); _cacheManager = CreateCacheManager(); }
private async Task BackgroundCleanup(ICacheStack cacheStack) { var cancellationToken = TokenSource.Token; while (!cancellationToken.IsCancellationRequested) { await Task.Delay(Frequency, cancellationToken); cancellationToken.ThrowIfCancellationRequested(); await cacheStack.CleanupAsync(); } }
public CacheService( IOptionsSnapshot <CacheConfig> cachingConfig, ILogger <CacheService> logger, ICacheStack cacheStack ) { _cacheConfig = cachingConfig.Value; _logger = logger; _cacheStack = cacheStack; (_expireAfter, _staleAfter) = cachingConfig.Value; }
private async Task BackgroundCleanup(ICacheStack cacheStack) { try { var cancellationToken = TokenSource.Token; while (!cancellationToken.IsCancellationRequested) { await Task.Delay(Frequency, cancellationToken); cancellationToken.ThrowIfCancellationRequested(); await cacheStack.CleanupAsync(); } } catch (Exception ex) when(ex is TaskCanceledException || ex is OperationCanceledException) { } }
public void Register(ICacheStack cacheStack) { if (IsRegistered) { throw new InvalidOperationException($"{nameof(RedisRemoteEvictionExtension)} can only be registered to one {nameof(ICacheStack)}"); } IsRegistered = true; Subscriber.Subscribe(RedisChannel, async(channel, value) => { string cacheKey = value; var shouldEvictLocally = false; lock (FlaggedRefreshesLockObj) { shouldEvictLocally = FlaggedRefreshes.Remove(cacheKey) == false; } if (shouldEvictLocally) { await cacheStack.EvictAsync(cacheKey); } }, CommandFlags.FireAndForget); }