@ -7,20 +7,20 @@ using System;
namespace Microsoft.eShopWeb.Web.Services
namespace Microsoft.eShopWeb.Web.Services
{
{
public class CachedCatalogService : ICatalogService
public class CachedCatalogViewModel Service : ICatalogViewModel Service
{
{
private readonly IMemoryCache _ cache ;
private readonly IMemoryCache _ cache ;
private readonly CatalogService _ catalogService ;
private readonly CatalogViewModel Service _ catalogViewModel Service ;
private static readonly string _ brandsKey = "brands" ;
private static readonly string _ brandsKey = "brands" ;
private static readonly string _ typesKey = "types" ;
private static readonly string _ typesKey = "types" ;
private static readonly string _ itemsKeyTemplate = "items-{0}-{1}-{2}-{3}" ;
private static readonly string _ itemsKeyTemplate = "items-{0}-{1}-{2}-{3}" ;
private static readonly TimeSpan _d efaultCacheDuration = TimeSpan . FromSeconds ( 3 0 ) ;
private static readonly TimeSpan _d efaultCacheDuration = TimeSpan . FromSeconds ( 3 0 ) ;
public CachedCatalogService ( IMemoryCache cache ,
public CachedCatalogViewModel Service ( IMemoryCache cache ,
CatalogService catalogService )
CatalogViewModel Service catalogViewModel Service )
{
{
_ cache = cache ;
_ cache = cache ;
_ catalogService = catalogService ;
_ catalogViewModel Service = catalogViewModel Service ;
}
}
public async Task < IEnumerable < SelectListItem > > GetBrands ( )
public async Task < IEnumerable < SelectListItem > > GetBrands ( )
@ -28,7 +28,7 @@ namespace Microsoft.eShopWeb.Web.Services
return await _ cache . GetOrCreateAsync ( _ brandsKey , async entry = >
return await _ cache . GetOrCreateAsync ( _ brandsKey , async entry = >
{
{
entry . SlidingExpiration = _d efaultCacheDuration ;
entry . SlidingExpiration = _d efaultCacheDuration ;
return await _ catalogService . GetBrands ( ) ;
return await _ catalogViewModel Service . GetBrands ( ) ;
} ) ;
} ) ;
}
}
@ -38,7 +38,7 @@ namespace Microsoft.eShopWeb.Web.Services
return await _ cache . GetOrCreateAsync ( cacheKey , async entry = >
return await _ cache . GetOrCreateAsync ( cacheKey , async entry = >
{
{
entry . SlidingExpiration = _d efaultCacheDuration ;
entry . SlidingExpiration = _d efaultCacheDuration ;
return await _ catalogService . GetCatalogItems ( pageIndex , itemsPage , brandId , typeId ) ;
return await _ catalogViewModel Service . GetCatalogItems ( pageIndex , itemsPage , brandId , typeId ) ;
} ) ;
} ) ;
}
}
@ -47,7 +47,7 @@ namespace Microsoft.eShopWeb.Web.Services
return await _ cache . GetOrCreateAsync ( _ typesKey , async entry = >
return await _ cache . GetOrCreateAsync ( _ typesKey , async entry = >
{
{
entry . SlidingExpiration = _d efaultCacheDuration ;
entry . SlidingExpiration = _d efaultCacheDuration ;
return await _ catalogService . GetTypes ( ) ;
return await _ catalogViewModel Service . GetTypes ( ) ;
} ) ;
} ) ;
}
}
}
}