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); }
public async Task EvictAsync(string cacheKey) { _logger.LogDebug("Evicting cache with key: {CacheKey}", cacheKey); await _cacheStack.EvictAsync(cacheKey); }