Skip to content

Commit

Permalink
Minor improvements - Add to the cache - handler - get all manufacturer
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofPajak committed Apr 2, 2020
1 parent e0b8fb1 commit 35ec48f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions Grand.Web/Controllers/CatalogController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public virtual async Task<IActionResult> Manufacturer(string manufacturerId, Cat
public virtual async Task<IActionResult> ManufacturerAll()
{
var model = await _mediator.Send(new GetManufacturerAll() {
Customer = _workContext.CurrentCustomer,
Language = _workContext.WorkingLanguage,
Store = _storeContext.CurrentStore
});
Expand Down
17 changes: 16 additions & 1 deletion Grand.Web/Features/Handlers/Catalog/GetManufacturerAllHandler.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using Grand.Core.Domain.Media;
using Grand.Core.Caching;
using Grand.Core.Domain.Media;
using Grand.Services.Catalog;
using Grand.Services.Customers;
using Grand.Services.Localization;
using Grand.Services.Media;
using Grand.Web.Extensions;
using Grand.Web.Features.Models.Catalog;
using Grand.Web.Infrastructure.Cache;
using Grand.Web.Models.Catalog;
using Grand.Web.Models.Media;
using MediatR;
Expand All @@ -18,20 +21,32 @@ public class GetManufacturerAllHandler : IRequestHandler<GetManufacturerAll, ILi
private readonly IManufacturerService _manufacturerService;
private readonly IPictureService _pictureService;
private readonly ILocalizationService _localizationService;
private readonly ICacheManager _cacheManager;
private readonly MediaSettings _mediaSettings;

public GetManufacturerAllHandler(IManufacturerService manufacturerService,
IPictureService pictureService,
ILocalizationService localizationService,
ICacheManager cacheManager,
MediaSettings mediaSettings)
{
_manufacturerService = manufacturerService;
_pictureService = pictureService;
_localizationService = localizationService;
_cacheManager = cacheManager;
_mediaSettings = mediaSettings;
}

public async Task<IList<ManufacturerModel>> Handle(GetManufacturerAll request, CancellationToken cancellationToken)
{
string cacheKey = string.Format(ModelCacheEventConst.MANUFACTURER_ALL_MODEL_KEY,
request.Language.Id,
string.Join(",", request.Customer.GetCustomerRoleIds()),
request.Store.Id);
return await _cacheManager.GetAsync(cacheKey, () => PrepareManufacturerAll(request));
}

private async Task<List<ManufacturerModel>> PrepareManufacturerAll(GetManufacturerAll request)
{
var model = new List<ManufacturerModel>();
var manufacturers = await _manufacturerService.GetAllManufacturers(storeId: request.Store.Id);
Expand Down
4 changes: 3 additions & 1 deletion Grand.Web/Features/Models/Catalog/GetManufacturerAll.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Grand.Core.Domain.Localization;
using Grand.Core.Domain.Customers;
using Grand.Core.Domain.Localization;
using Grand.Core.Domain.Stores;
using Grand.Web.Models.Catalog;
using MediatR;
Expand All @@ -9,6 +10,7 @@ namespace Grand.Web.Features.Models.Catalog
public class GetManufacturerAll : IRequest<IList<ManufacturerModel>>
{
public Store Store { get; set; }
public Customer Customer { get; set; }
public Language Language { get; set; }
}
}
10 changes: 10 additions & 0 deletions Grand.Web/Infrastructure/Cache/ModelCacheEventConst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static class ModelCacheEventConst
/// </remarks>
public const string MANUFACTURER_HOMEPAGE_KEY = "Grand.pres.manufacturer.navigation.homepage-{0}-{1}";


/// <summary>
/// Key for caching of manufacturer displayed on home page
/// </summary>
Expand All @@ -54,6 +55,15 @@ public static class ModelCacheEventConst
/// </remarks>
public const string MANUFACTURER_FEATURED_PRODUCT_HOMEPAGE_KEY = "Grand.pres.manufacturer.navigation.homepage-fp-{0}-{1}-{2}";

/// <summary>
/// Key for List of ManufacturerModel caching
/// </summary>
/// <remarks>
/// {0} : language id
/// {1} : comma separated list of customer roles
/// {2} : current store ID
/// </remarks>
public const string MANUFACTURER_ALL_MODEL_KEY = "Grand.pres.manufacturer.navigation.all-{0}-{1}-{2}";

/// <summary>
/// Key for VendorNavigationModel caching
Expand Down

0 comments on commit 35ec48f

Please sign in to comment.