Exemplo n.º 1
0
        /// <summary>
        /// Removes the specified cacheKey async.
        /// </summary>
        /// <returns>The async.</returns>
        /// <param name="cacheKey">Cache key.</param>
        public async Task RemoveAsync(string cacheKey)
        {
            ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));

            //distributed cache at first
            await _distributedCache.RemoveAsync(cacheKey);

            await _localCache.RemoveAsync(cacheKey);

            //send message to bus
            await _bus.PublishAsync(_options.TopicName, new EasyCachingMessage { Id = _cacheId, CacheKeys = new string[] { cacheKey } });
        }
Exemplo n.º 2
0
        public async Task Send_Msg_Async_Throw_Exception_Should_Not_Break()
        {
            CancellationToken token = new CancellationToken();

            A.CallTo(() => fakeBus.PublishAsync("test_topic", A <EasyCachingMessage> ._, token)).ThrowsAsync((arg) => new Exception());

            await fakeHybrid.RemoveAsync("fake-remove");

            Assert.True(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Removes the specified cacheKey async.
        /// </summary>
        /// <returns>The async.</returns>
        /// <param name="cacheKey">Cache key.</param>
        public async Task RemoveAsync(string cacheKey)
        {
            ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));

            try
            {
                // distributed cache at first
                await _distributedCache.RemoveAsync(cacheKey);
            }
            catch (Exception ex)
            {
                _logger?.LogError(ex, "remove cache key [{0}] error", cacheKey);
            }

            await _localCache.RemoveAsync(cacheKey);

            // send message to bus
            await _bus.PublishAsync(_options.TopicName, new EasyCachingMessage { Id = _cacheId, CacheKeys = new string[] { cacheKey } });
        }