public async Task <IActionResult> Index(int?page, string username, int?min, int?max, string types, string sortBy, bool descending) { var resultTransactions = await transcationServices.SearchTransactionAsync(username, min, max, types?.Split(','), sortBy, descending); var pagedTransactions = await resultTransactions.ToPagedListAsync(page ?? 1, PAGE_SIZE); var cachedSelectListTypes = await cache.GetOrCreateAsync("TransactionTypes", async entry => { entry.SlidingExpiration = TimeSpan.FromHours(4); var transactionTypes = await transcationServices.GetTypesAsync(); return(transactionTypes.Select(t => new SelectListItem(t, t))); }); var cachedSelectListSortProps = cache.GetOrCreate("SortProperties", entry => { entry.SlidingExpiration = TimeSpan.FromHours(4); return(typeof(TransactionViewModel).GetProperties().Select(p => new SelectListItem(p.Name, p.Name))); }); var model = new IndexViewModel { TransactionTypes = cachedSelectListTypes, PagedTransactions = pagedTransactions, SortProp = cachedSelectListSortProps }; return(View(model)); }