Example #1
0
        /// <summary>
        /// Processes the evict async.
        /// </summary>
        /// <returns>The evict async.</returns>
        /// <param name="context">Context.</param>
        /// <param name="isBefore">If set to <c>true</c> is before.</param>
        private async Task ProcessEvictAsync(AspectContext context, bool isBefore)
        {
            if (GetMethodAttributes(context.ServiceMethod).FirstOrDefault(x => x.GetType() == typeof(EasyCachingEvictAttribute)) is EasyCachingEvictAttribute attribute && attribute.IsBefore == isBefore)
            {
                try
                {
                    if (attribute.IsAll)
                    {
                        //If is all , clear all cached items which cachekey start with the prefix.
                        var cachePrefix = KeyGenerator.GetCacheKeyPrefix(context.ServiceMethod, attribute.CacheKeyPrefix);

                        await _cacheProvider.RemoveByPrefixAsync(cachePrefix);
                    }
                    else
                    {
                        //If not all , just remove the cached item by its cachekey.
                        var cacheKey = KeyGenerator.GetCacheKey(context.ServiceMethod, context.Parameters, attribute.CacheKeyPrefix);

                        await _cacheProvider.RemoveAsync(cacheKey);
                    }
                }
                catch (Exception ex)
                {
                    if (!attribute.IsHightAvailability)
                    {
                        throw;
                    }
                    else
                    {
                        Logger?.LogError(new EventId(), ex, $"Cache provider \"{_cacheProvider.Name}\" remove error.");
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Removes cached item by cachekey's prefix async.
        /// </summary>
        /// <returns>The by prefix async.</returns>
        /// <param name="prefix">Prefix.</param>
        public async Task RemoveByPrefixAsync(string prefix)
        {
            ArgumentCheck.NotNullOrWhiteSpace(prefix, nameof(prefix));

            await _localCachingProvider.RemoveByPrefixAsync(prefix);

            await _distributedCachingProvider.RemoveByPrefixAsync(prefix);
        }
        /// <summary>
        /// Removes the by prefix async.
        /// </summary>
        /// <returns>The by prefix async.</returns>
        /// <param name="prefix">Prefix.</param>
        public async Task RemoveByPrefixAsync(string prefix)
        {
            ArgumentCheck.NotNullOrWhiteSpace(prefix, nameof(prefix));

            await _localCache.RemoveByPrefixAsync(prefix);

            await _distributedCache.RemoveByPrefixAsync(prefix);

            //send message to bus in order to notify other clients.
            await _bus.PublishAsync(_options.TopicName, new EasyCachingMessage { Id = _cacheId, CacheKeys = new string[] { prefix }, IsPrefix = true });
        }
Example #4
0
        /// <summary>
        /// Removes the by prefix async.
        /// </summary>
        /// <returns>The by prefix async.</returns>
        /// <param name="prefix">Prefix.</param>
        public async Task RemoveByPrefixAsync(string prefix)
        {
            ArgumentCheck.NotNullOrWhiteSpace(prefix, nameof(prefix));

            try
            {
                await _distributedCache.RemoveByPrefixAsync(prefix);
            }
            catch (Exception ex)
            {
                _logger?.LogError(ex, "remove by prefix [{0}] error", prefix);
            }

            await _localCache.RemoveByPrefixAsync(prefix);

            // send message to bus in order to notify other clients.
            await _bus.PublishAsync(_options.TopicName, new EasyCachingMessage { Id = _cacheId, CacheKeys = new string[] { prefix }, IsPrefix = true });
        }
Example #5
0
 /// <summary>
 /// Removes cache by key prefix
 /// </summary>
 public async Task RemoveByPrefixAsync(string prefix)
 {
     await _provider.RemoveByPrefixAsync(prefix);
 }
Example #6
0
 public async Task RemoveByPrefix_Async_Should_Throw_ArgumentNullException_When_Prefix_IsNullOrWhiteSpace(string preifx)
 {
     await Assert.ThrowsAsync <ArgumentNullException>(async() => await _provider.RemoveByPrefixAsync(preifx));
 }
Example #7
0
 /// <summary>
 /// Removes cached item by cachekey's prefix async.
 /// </summary>
 /// <param name="prefix">Prefix of CacheKey.</param>
 /// <param name="cancellationToken">cancellationToken</param>
 /// <returns>Task</returns>
 public Task RemoveByPrefixAsync(string prefix, CancellationToken cancellationToken = default)
 {
     return(_easyCachingProvider.RemoveByPrefixAsync(prefix));
 }
Example #8
0
 public async Task ClearCache(CancellationToken token)
 {
     await _provider.RemoveByPrefixAsync(KeyPrefix);
 }
Example #9
0
 public Task RemoveByPrefixAsync(string prefix)
 {
     return(_provider.RemoveByPrefixAsync(prefix));
 }
 public async Task ResetCacheAsync(string cachekey)
 {
     await _cachingProvider.RemoveByPrefixAsync(cachekey);
 }