private void ProcessDelayedActionsQueue()
        {
            var dequeuedBuffer = new List <DelayedInvalidationParameters>();

            try
            {
                var invalidationTasks = new List <Task>();
                while (_queue.TryDequeue(out var item) &&
                       !_cancellationTokenSource.IsCancellationRequested)
                {
                    if (DateTime.UtcNow < item.DueTime)
                    {
                        dequeuedBuffer.Add(item);
                    }
                    else
                    {
                        invalidationTasks.Add(_cacheAdapter.InvalidateCachedMethodResults(item.Methods));
                    }
                }

                Task.WaitAll(invalidationTasks.ToArray(), _cancellationTokenSource.Token);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex,
                                 "Error occurred while trying to invalidate a cached method(s) (delayed)!");
            }
            finally
            {
                dequeuedBuffer.ForEach(_queue.Enqueue);
            }
        }
        private async Task HandleInvalidatesAttribute(InvalidatesCacheAttribute attribute,
                                                      ActionExecutingContext context)
        {
            var invalidationParameters = new List <MethodInvalidationParameters>();

            foreach (var cacheGroup in attribute.CacheGroups)
            {
                if (!_cachedMethodsPerGroup.TryGetValue(cacheGroup, out var methods))
                {
                    continue;
                }

                foreach (var cachedMethod in methods)
                {
                    var targetMethodCacheAttribute = cachedMethod.GetCustomAttribute <CachedAttribute>();
                    var scopeValue =
                        _cacheParametersResolver.ResolveScopeValue(targetMethodCacheAttribute.ScopeName, context);
                    invalidationParameters.Add(new MethodInvalidationParameters(
                                                   cachedMethod.GetUniqueIdentifier(), targetMethodCacheAttribute.ScopeName, scopeValue));
                }
            }

            await _cacheAdapter.InvalidateCachedMethodResults(invalidationParameters);
        }