예제 #1
0
        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);
                    }
                }
            });
        }
예제 #2
0
 public void Register(ICacheStack cacheStack)
 {
     foreach (var extension in AllExtensions)
     {
         extension.Register(cacheStack);
     }
 }
예제 #3
0
        public void Register(ICacheStack cacheStack)
        {
            if (BackgroundTask != null)
            {
                throw new InvalidOperationException($"{nameof(AutoCleanupExtension)} can only be registered to one {nameof(ICacheStack)}");
            }

            BackgroundTask = BackgroundCleanup(cacheStack);
        }
예제 #4
0
        public void Register(ICacheStack cacheStack)
        {
            if (RegisteredStack != null)
            {
                throw new InvalidOperationException($"{nameof(RedisLockExtension)} can only be registered to one {nameof(ICacheStack)}");
            }

            RegisteredStack = cacheStack;
        }
예제 #5
0
 public LocalGetBenchmark()
 {
     _concurrentDictionary = CreateConcurrentDictionary();
     _modernCache          = CreateModernCache();
     _cacheTower           = CreateCacheTower();
     _foundatio            = CreateFoundatio();
     _lazyCache            = CreateLazyCache();
     _fusionCache          = CreateFusionCache();
     _easyCache            = CreateEasyCache();
     _cacheManager         = CreateCacheManager();
 }
예제 #6
0
        private async Task BackgroundCleanup(ICacheStack cacheStack)
        {
            var cancellationToken = TokenSource.Token;

            while (!cancellationToken.IsCancellationRequested)
            {
                await Task.Delay(Frequency, cancellationToken);

                cancellationToken.ThrowIfCancellationRequested();
                await cacheStack.CleanupAsync();
            }
        }
예제 #7
0
    public CacheService(
        IOptionsSnapshot <CacheConfig> cachingConfig,
        ILogger <CacheService> logger,
        ICacheStack cacheStack
        )
    {
        _cacheConfig = cachingConfig.Value;
        _logger      = logger;
        _cacheStack  = cacheStack;

        (_expireAfter, _staleAfter) = cachingConfig.Value;
    }
예제 #8
0
        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);
        }