コード例 #1
0
ファイル: ServiceBase.cs プロジェクト: sschem/UsersAdmin
        public async Task <TDto> AddAsync(TDto dto)
        {
            var entity = _mapper.Map <TEntity>(dto);

            var obtainedEntity = await this.Repository.SelectByIdAsync(entity.GetIds);

            if (obtainedEntity != null)
            {
                throw new WarningException(this.EntityAlreadyExists);
            }

            await this.Repository.InsertAsync(entity);

            await _unitOfWork.CommitAsync();

            _ = _cache.RemoveAsync(GET_ALL_CACHE_KEY);

            return(dto);
        }
 private async Task RemoveCache()
 {
     try
     {
         await _cache.RemoveAsync(CacheKeys.CountriesKey);
     }
     catch (RedisConnectionException ex)
     {
         _logger.LogCritical(303, ex, ex.Message);
     }
 }
コード例 #3
0
ファイル: CacheRepo.cs プロジェクト: Nebbia/RedisRepo
        public virtual async Task RemoveFromCacheAsync(T entity)
        {
            if (!CustomIndicesAreSet)
            {
                SetCustomCacheIndices(entity);
                CustomIndicesAreSet = true;
            }
            var primaryEntityId = PrimaryEntityIdLocator(entity);
            var primaryCacheKey = PrimaryCacheKeyFormatter(primaryEntityId);
            await _appCache.RemoveAsync(primaryCacheKey, PartitionNameFormatter()).ConfigureAwait(false);

            await RemoveCustomIndicesAsync(entity).ConfigureAwait(false);
        }
コード例 #4
0
        public async Task <TResponse> RunAsync <TRequest, TResponse>(TRequest request,
                                                                     CancellationToken cancellationToken,
                                                                     Func <TRequest, CancellationToken, Task <TResponse> > next) where TRequest : IRequest <TResponse>
        {
            if (!(request is IEnableInterceptor <CacheResponseInterceptor>))
            {
                return(await next.Invoke(request, cancellationToken));
            }

            _logger.Debug("CacheResponseInterceptor started");
            var cacheRequest = request as ICacheResponse;

            if (cacheRequest != null)
            {
                _logger.Debug($"Retrieving response from cache. Key: {cacheRequest.CacheKey}");
                var responseFromCache = await _appCache.GetAsync <TResponse>(cacheRequest.CacheKey,
                                                                             cancellationToken, absoluteExpiration : cacheRequest.AbsoluteExpiration);

                if (!EqualityComparer <TResponse> .Default.Equals(responseFromCache, default))
                {
                    _logger.Debug("Returning response from cache");
                    _logger.Debug("CacheResponseInterceptor ended");
                    return(responseFromCache);
                }
            }

            var response = await next(request, cancellationToken);

            if (cacheRequest != null)
            {
                _logger.Debug($"Saving response in cache. Key: {cacheRequest.CacheKey}");
                await _appCache.SetAsync(cacheRequest.CacheKey, response,
                                         cancellationToken, cacheRequest.AbsoluteExpiration);
            }

            if (request is IClearCachedResponse clearCacheRequest)
            {
                _logger.Debug($"Removing response from cache. Key: {clearCacheRequest.CacheKey}");
                await _appCache.RemoveAsync(clearCacheRequest.CacheKey, cancellationToken);
            }

            _logger.Debug("CacheResponseInterceptor ended");
            return(response);
        }
コード例 #5
0
        public async Task <FunqResult> DeleteMinionAsync(Guid minionId)
        {
            await _appCache.RemoveAsync(minionId.ToString(), typeof(Minion).Name);

            return(FunqFactory.KeepGroovin("Deleted the minion"));
        }