Exemple #1
0
        private async Task <T> TryAdd(T value)
        {
            var maxAttempted = 0;

            while (maxAttempted < _connectionOptions.RetryCount)
            {
                try
                {
                    return(await _instance.AddAsync(value));
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "can not add item");

                    var continues = _connectionOptions.Handles?.Invoke(ex);

                    if (continues == false)
                    {
                        return(null);
                    }
                }

                if (_connectionOptions.IntervalRetry > 0)
                {
                    await Task.Delay(TimeSpan.FromSeconds(_connectionOptions.IntervalRetry));
                }

                maxAttempted++;
            }

            _connectionOptions.FallBackAction?.Invoke(nameof(TryAdd), value);

            return(null);
        }
Exemple #2
0
 public async Task AddItem(string key, string value, TimeSpan?expiredIn = null)
 {
     var cacheItem = new CacheItem(key, value, _repository, expiredIn);
     await _repository.AddAsync(cacheItem);
 }