public void ReturnCatalogItemCacheKey() { var pageIndex = 0; int?brandId = null; int?typeId = null; var culture = CultureInfo.CurrentCulture.Name; var result = CacheHelpers.GenerateCatalogItemCacheKey(pageIndex, Constants.ITEMS_PER_PAGE, culture, brandId, typeId); Assert.Equal("items-0-10--", result); }
public async Task <CatalogIndexViewModel> GetCatalogItems(int pageIndex, int itemsPage, int?brandId, int?typeId) { var cacheKey = CacheHelpers.GenerateCatalogItemCacheKey(pageIndex, itemsPage, brandId, typeId); return(await _cache.GetOrCreateAsync(cacheKey, async entry => { entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration; // calling second class's GetCatalogItems from this class's GetCatalogItems() because only the second class contains the business logic return await _catalogViewModelService.GetCatalogItems(pageIndex, itemsPage, brandId, typeId); })); }
public async Task <CatalogIndexViewModel> GetCatalogItems(int pageIndex, int itemsPage, int?brandId, int?typeId) { var cacheKey = CacheHelpers.GenerateCatalogItemCacheKey(pageIndex, Constants.ITEMS_PER_PAGE, brandId, typeId); _cache.Remove(cacheKey);//remove this Serhat var catalog = await _cache.GetOrCreateAsync(cacheKey, async entry => { entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration; return(await _catalogViewModelService.GetCatalogItems(pageIndex, itemsPage, brandId, typeId)); }); return(catalog); }
public async Task OnGet(CatalogIndexViewModel catalogModel, int?pageId, bool convertPrice = true) { var cacheKey = CacheHelpers.GenerateCatalogItemCacheKey(pageId.GetValueOrDefault(), Constants.ITEMS_PER_PAGE, catalogModel.SearchFilter, catalogModel.BrandFilterApplied, catalogModel.TypesFilterApplied, CultureInfo.CurrentCulture.Name); _cache.Remove(cacheKey); CatalogModel = await _catalogViewModelService.GetCatalogItems(pageId.GetValueOrDefault(), Constants.ITEMS_PER_PAGE, catalogModel.SearchFilter, catalogModel.BrandFilterApplied, catalogModel.TypesFilterApplied, convertPrice : false, HttpContext.RequestAborted); CatalogModel.ResultView = catalogModel.ResultView; // HACK CatalogModel.ResultViews = Enum <ResultView> .GetAll() .Select(resultView => new SelectListItem { Value = resultView.ToString(), Text = resultView.ToString() }); }
public async Task <CatalogIndexViewModel> GetCatalogItems( int pageIndex, int itemsPage, string searchText, int?brandId, int?typeId, bool convertPrice = true, CancellationToken cancellationToken = default(CancellationToken)) { var cacheKey = CacheHelpers.GenerateCatalogItemCacheKey(pageIndex, Constants.ITEMS_PER_PAGE, searchText, brandId, typeId, CultureInfo.CurrentCulture.Name); return(await _cache.GetOrCreateAsync(cacheKey, async entry => { entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration; return await((ICatalogViewModelService)_catalogViewModelService).GetCatalogItems( pageIndex, itemsPage, searchText, brandId, typeId, convertPrice, cancellationToken); })); }
/// <summary> /// Get catalog items /// </summary> /// <param name="catalogPageFiltersViewModel"></param> /// <param name="useCache"></param> /// <param name="convertPrice"></param> /// <param name="cancelattionToken"></param> /// <returns></returns> public async Task <CatalogIndexViewModel> GetCatalogItems(CatalogPageFiltersViewModel catalogPageFiltersViewModel, bool useCache, bool convertPrice = false, CancellationToken cancelattionToken = default(CancellationToken)) { if (useCache) { var cacheKey = CacheHelpers.GenerateCatalogItemCacheKey(catalogPageFiltersViewModel); return(await _cache.GetOrCreateAsync(cacheKey, async entry => { entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration; return await _catalogViewModelService.GetCatalogItems(catalogPageFiltersViewModel, useCache, convertPrice, cancelattionToken); })); } else { return(await _catalogViewModelService.GetCatalogItems(catalogPageFiltersViewModel, useCache, convertPrice, cancelattionToken)); } }
public void ReturnCatalogItemCacheKey(int pageIndex, int itemPerPage, string searchText, int?brandId, int?typeId, string cultureName, string expectedResult, Type exceptionType = null) { if (string.IsNullOrEmpty(expectedResult)) { if (exceptionType == null) { throw new Exception("Missing exception type to check"); } Assert.Throws(exceptionType, () => CacheHelpers.GenerateCatalogItemCacheKey(pageIndex, itemPerPage, searchText, brandId, typeId, cultureName)); } else { var result = CacheHelpers.GenerateCatalogItemCacheKey(pageIndex, itemPerPage, searchText, brandId, typeId, cultureName); Assert.Equal(expectedResult, result); } }
public void ReturnCatalogItemCacheKey( int pageIndex, int itemPerPage, string culture, int?brandId, int?typeId, string searchText, NamesOrderBy?orderBy, Ordination order, string expectedResult, Type exceptionType = null ) { var catalogPageFiltersViewModel = new CatalogPageFiltersViewModel() { PageId = pageIndex, ItemsPerPage = itemPerPage, Culture = culture, BrandFilter = brandId, TypesFilter = typeId, SearchTextFilter = searchText, OrderBy = orderBy, Order = order }; if (string.IsNullOrEmpty(expectedResult)) { if (exceptionType == null) { throw new Exception("Missing exception type to check"); } Assert.Throws( exceptionType, () => CacheHelpers.GenerateCatalogItemCacheKey(catalogPageFiltersViewModel)); } else { var result = CacheHelpers.GenerateCatalogItemCacheKey(catalogPageFiltersViewModel); Assert.Equal(expectedResult, result); } }
public async Task OnGet(CatalogIndexViewModel catalogModel, int?pageId) { var cacheKey = CacheHelpers.GenerateCatalogItemCacheKey( pageId.GetValueOrDefault(), Constants.ITEMS_PER_PAGE, catalogModel.SearchText, catalogModel.BrandFilterApplied, catalogModel.TypesFilterApplied); _cache.Remove(cacheKey); CatalogModel = await _catalogViewModelService.GetCatalogItems( pageId.GetValueOrDefault(), Constants.ITEMS_PER_PAGE, catalogModel.SearchText, catalogModel.BrandFilterApplied, catalogModel.TypesFilterApplied, convertPrice : false, HttpContext.RequestAborted); }