示例#1
0
        protected virtual async Task <SearchResult <TD> > GetByFiltersWithCache(FilterBase filter, Func <FilterBase, PaginateResult <T>, IEnumerable <TD> > MapperDomainToDto)
        {
            var filterKey = filter.CompositeKey();

            if (filter.ByCache)
            {
                if (this._cache.ExistsKey(filterKey))
                {
                    return((SearchResult <TD>) this._cache.Get(filterKey));
                }
            }

            var paginateResultOptimize = await this._serviceBase.GetByFiltersPaging(filter as TF);

            var result  = MapperDomainToDto(filter, paginateResultOptimize);
            var summary = this.Summary(paginateResultOptimize);

            var searchResult = new SearchResult <TD>
            {
                DataList = result,
                Summary  = summary,
            };

            if (filter.ByCache)
            {
                if (!searchResult.DataList.IsAny())
                {
                    return(searchResult);
                }
                this._cache.Add(filterKey, searchResult, filter.CacheExpiresTime);
                this.AddTagCache(filterKey, this._serviceBase.GetTagNameCache());
            }

            return(searchResult);
        }
        protected virtual async Task <TD> GetOneWithCache(FilterBase filter, Func <FilterBase, T, TD> MapperDomainToDto)
        {
            var filterKey = filter.CompositeKey(this._user);

            if (filter.ByCache)
            {
                var cacheResult = this._cache.Get <TD>(filterKey);
                if (cacheResult.IsNotNull())
                {
                    return(cacheResult);
                }
            }

            var resultDomain = await this._serviceBase.GetOne(filter as TF);

            var resultDto = MapperDomainToDto <TD>(filter, resultDomain);

            if (filter.ByCache)
            {
                if (resultDto.IsNull())
                {
                    return(resultDto);
                }
                this.AddCache(filter, filterKey, resultDto);
            }

            return(resultDto);
        }