public async Task <IResponse> RequestAsync(IRequest request, CancellationToken cancel)
        {
            try
            {
                if ((await _cacheClient.SearchKeysAsync(request.Address.Href)).Count() != 0)
                {
                    _logger.LogInformation($"Cache hit for: {request.Address.Href}");
                    return(await _cacheClient.GetAsync <CachedResponse>(request.Address.Href));
                }

                _logger.LogInformation($"Cache miss for: {request.Address.Href}");

                _logger.LogInformation($"requesting: {request.Address.Href}");
                Response response = (Response)await _innerRequestor.RequestAsync(request, cancel);

                _logger.LogInformation($"response recieved from: {request.Address.Href}");
                var cachedRequest = new CachedResponse(response);
                _logger.LogInformation($"caching entry: {request.Address.Href}");
                await _cacheClient.AddAsync(request.Address.Href, cachedRequest);

                return(cachedRequest);
            }
            catch (Exception ex) {
                throw;
            }
        }
        public async Task <T> Add(T entity)
        {
            try
            {
                await redis.AddAsync(key, entity);

                return(await Get());
            }
            catch (Exception ex)
            {
                throw new RepositoryException("Error con redis", ex);
            }
        }
Пример #3
0
        public async Task <T> AddItemAsync(T value)
        {
            var key = FindKey();
            var id  = key.GetValue(value);

            if (string.IsNullOrEmpty(id?.ToString()))
            {
                id = $"{typeof(T).Name}_{Guid.NewGuid()}";
            }

            key.SetValue(value, id);

            var isSuccess = await _cacheClient.AddAsync(id.ToString(), value);

            return((isSuccess) ? value : throw new InvalidOperationException());
        }
Пример #4
0
 public Task SetAsync <T>(CacheItem <T> item) where T : class => Client.AddAsync(item.Key, item.Data, item.ExpiresAt, item.ExpiresIn, item.FireAndForget);
Пример #5
0
 public async Task SetAsync <T>(string key, T data, TimeSpan?cacheTime = null) where T : class
 {
     await _retryPolicy.ExecuteAsync(() => _cacheClient.AddAsync(key, data, cacheTime ?? _cacheTime, false));
 }
Пример #6
0
 public async Task <bool> Store <T>(string key, T value)
 {
     return(await cacheClient.AddAsync(key, value));
 }
 public async Task SetNotification(Notification notification)
 {
     await _cache.AddAsync(_cacheKey, notification);
 }