|
|
|
@ -7,20 +7,20 @@ using System; |
|
|
|
|
|
|
|
namespace Microsoft.eShopWeb.Web.Services |
|
|
|
{ |
|
|
|
public class CachedCatalogService : ICatalogService |
|
|
|
public class CachedCatalogViewModelService : ICatalogViewModelService |
|
|
|
{ |
|
|
|
private readonly IMemoryCache _cache; |
|
|
|
private readonly CatalogService _catalogService; |
|
|
|
private readonly CatalogViewModelService _catalogViewModelService; |
|
|
|
private static readonly string _brandsKey = "brands"; |
|
|
|
private static readonly string _typesKey = "types"; |
|
|
|
private static readonly string _itemsKeyTemplate = "items-{0}-{1}-{2}-{3}"; |
|
|
|
private static readonly TimeSpan _defaultCacheDuration = TimeSpan.FromSeconds(30); |
|
|
|
|
|
|
|
public CachedCatalogService(IMemoryCache cache, |
|
|
|
CatalogService catalogService) |
|
|
|
public CachedCatalogViewModelService(IMemoryCache cache, |
|
|
|
CatalogViewModelService catalogViewModelService) |
|
|
|
{ |
|
|
|
_cache = cache; |
|
|
|
_catalogService = catalogService; |
|
|
|
_catalogViewModelService = catalogViewModelService; |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<IEnumerable<SelectListItem>> GetBrands() |
|
|
|
@ -28,7 +28,7 @@ namespace Microsoft.eShopWeb.Web.Services |
|
|
|
return await _cache.GetOrCreateAsync(_brandsKey, async entry => |
|
|
|
{ |
|
|
|
entry.SlidingExpiration = _defaultCacheDuration; |
|
|
|
return await _catalogService.GetBrands(); |
|
|
|
return await _catalogViewModelService.GetBrands(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@ -38,7 +38,7 @@ namespace Microsoft.eShopWeb.Web.Services |
|
|
|
return await _cache.GetOrCreateAsync(cacheKey, async entry => |
|
|
|
{ |
|
|
|
entry.SlidingExpiration = _defaultCacheDuration; |
|
|
|
return await _catalogService.GetCatalogItems(pageIndex, itemsPage, brandId, typeId); |
|
|
|
return await _catalogViewModelService.GetCatalogItems(pageIndex, itemsPage, brandId, typeId); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@ -47,7 +47,7 @@ namespace Microsoft.eShopWeb.Web.Services |
|
|
|
return await _cache.GetOrCreateAsync(_typesKey, async entry => |
|
|
|
{ |
|
|
|
entry.SlidingExpiration = _defaultCacheDuration; |
|
|
|
return await _catalogService.GetTypes(); |
|
|
|
return await _catalogViewModelService.GetTypes(); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |