public async Task<GetCategoryOutput> GetAllByTaxonomy(TaxonomyEnum taxonomy) { string cacheKey = "GetAllByTaxonomy_"+Enum.GetName(typeof(TaxonomyEnum), taxonomy); //创建缓存对象 AsyncThreadSafeObjectCache<GetCategoryOutput> cache = new AsyncThreadSafeObjectCache<GetCategoryOutput>(System.Runtime.Caching.MemoryCache.Default, TimeSpan.FromSeconds(120)); GetCategoryOutput output = await cache.GetAsync(cacheKey, async () => { var tagCategory = await _categoryRepository.GetAllListAsync(w => w.Taxonomy == taxonomy); output = new GetCategoryOutput { CategoryCollection = Mapper.Map<List<CategoryDto>>(tagCategory) }; //插入到缓存 cache.Set(cacheKey, output); //返回数据 return output; }); return output; }
public async Task<CategoryPageOutput> GetByPage(CategoryPageInput input, TaxonomyEnum taxonomy) { //跳过条数 var skipCount = (input.PageIndex - 1) * input.PageSize; //获取条数 var maxResultCount = input.PageSize; //获取总条数 var totalCount = await _categoryRepository.CountAsync(w => w.Taxonomy == taxonomy); //获取集合 var categoryList = await _categoryRepository.GetEnumerableByPage(skipCount, maxResultCount, taxonomy, o => o.CreationTime); var result = new CategoryPageOutput { TotalCount = totalCount, Items = Mapper.Map<IReadOnlyList<CategoryDto>>(categoryList), PageIndex = input.PageIndex }; return result; }