using Nop.Core.Domain.Catalog; using Nop.Services.Caching; using Nop.Services.Discounts; namespace Nop.Services.Catalog.Caching; /// /// Represents a category cache event consumer /// public partial class CategoryCacheEventConsumer : CacheEventConsumer { /// /// Clear cache data /// /// Entity /// Entity event type /// A task that represents the asynchronous operation protected override async Task ClearCacheAsync(Category entity, EntityEventType entityEventType) { await RemoveByPrefixAsync(NopCatalogDefaults.CategoriesByParentCategoryPrefix, entity); await RemoveByPrefixAsync(NopCatalogDefaults.CategoriesByParentCategoryPrefix, entity.ParentCategoryId); await RemoveByPrefixAsync(NopCatalogDefaults.CategoriesChildIdsPrefix, entity); await RemoveByPrefixAsync(NopCatalogDefaults.CategoriesChildIdsPrefix, entity.ParentCategoryId); await RemoveByPrefixAsync(NopCatalogDefaults.CategoriesHomepagePrefix); await RemoveByPrefixAsync(NopCatalogDefaults.CategoryBreadcrumbPrefix); await RemoveByPrefixAsync(NopCatalogDefaults.CategoryProductsNumberPrefix); await RemoveByPrefixAsync(NopDiscountDefaults.CategoryIdsPrefix); if (entityEventType == EntityEventType.Delete) { await RemoveAsync(NopCatalogDefaults.SpecificationAttributeOptionsByCategoryCacheKey, entity); await RemoveByPrefixAsync(NopCatalogDefaults.ManufacturersByCategoryWithIdPrefix, entity); } if (entityEventType == EntityEventType.Delete || !entity.Published) await RemoveByPrefixAsync(NopCatalogDefaults.ProductCategoriesByProductWithoutIdPrefix); await RemoveAsync(NopDiscountDefaults.AppliedDiscountsCacheKey, nameof(Category), entity); await base.ClearCacheAsync(entity, entityEventType); } }