Example #1
0
        protected virtual async Task SetAllAsync_Should_Succeed()
        {
            var dict = GetMultiDict("setallasync:");

            await _provider.SetAllAsync(dict, _defaultTs);

            var res1 = _provider.Get <string>("setallasync:key:1");
            var res2 = _provider.Get <string>("setallasync:key:2");

            Assert.Equal("value1", res1.Value);
            Assert.Equal("value2", res2.Value);
        }
Example #2
0
        /// <summary>
        /// Sets all async.
        /// </summary>
        /// <returns>The all async.</returns>
        /// <param name="values">Values.</param>
        /// <param name="expiration">Expiration.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public async Task SetAllAsync <T>(IDictionary <string, T> values, TimeSpan expiration) where T : class
        {
            ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration));
            ArgumentCheck.NotNullAndCountGTZero(values, nameof(values));

            await _localCachingProvider.SetAllAsync(values, expiration);

            try
            {
                await _distributedCachingProvider.SetAllAsync(values, expiration);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
        }
Example #3
0
        /// <summary>
        /// Sets all async.
        /// </summary>
        /// <returns>The all async.</returns>
        /// <param name="value">Value.</param>
        /// <param name="expiration">Expiration.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public async Task SetAllAsync <T>(IDictionary <string, T> value, TimeSpan expiration)
        {
            await _localCache.SetAllAsync(value, expiration);

            try
            {
                await _distributedCache.SetAllAsync(value, expiration);
            }
            catch (Exception ex)
            {
                _logger?.LogError(ex, "set all from distributed provider error [{0}]", string.Join(",", value.Keys));
            }

            // send message to bus
            await _bus.PublishAsync(_options.TopicName, new EasyCachingMessage { Id = _cacheId, CacheKeys = value.Keys.ToArray(), IsPrefix = false });
        }
 /// <summary>
 /// Sets all async.
 /// </summary>
 /// <returns>The all async.</returns>
 /// <param name="value">Value.</param>
 /// <param name="expiration">Expiration.</param>
 /// <typeparam name="T">The 1st type parameter.</typeparam>
 public async Task SetAllAsync <T>(IDictionary <string, T> value, TimeSpan expiration)
 {
     await _distributedCache.SetAllAsync(value, expiration);
 }
Example #5
0
        /// <summary>
        /// Sets all async.
        /// </summary>
        /// <typeparam name="T">Type of cache value</typeparam>
        /// <param name="value">Dictionary of key/value cache items</param>
        /// <param name="expirationMinutes">Expiration in minutes</param>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns>Task</returns>
        public Task SetAllAsync <T>(IDictionary <string, T> value, int?expirationMinutes = null, CancellationToken cancellationToken = default)
        {
            var timespan = TimeSpan.FromMinutes(expirationMinutes ?? _options.DefaultCacheMinutes);

            return(_easyCachingProvider.SetAllAsync(value, timespan));
        }