using Nop.Core.Events; using Nop.Core.Caching; using Nop.Services.Events; using System.Threading.Tasks; using Nop.Core.Domain.Configuration; namespace Nop.Plugin.Widgets.NopCliGeneric.Infrastructure.Cache { /// /// Model cache event consumer (used for caching of presentation layer models) /// public partial class ModelCacheEventConsumer : IConsumer>, IConsumer>, IConsumer> { /// /// Key for caching /// public const string PICTURE_URL_PATTERN_KEY = "Nop.plugins.widgets.NopCliGeneric"; private readonly IStaticCacheManager _staticCacheManager; public ModelCacheEventConsumer(IStaticCacheManager staticCacheManager) { _staticCacheManager = staticCacheManager; } /// A task that represents the asynchronous operation public async Task HandleEventAsync(EntityInsertedEvent eventMessage) { await _staticCacheManager.RemoveByPrefixAsync(PICTURE_URL_PATTERN_KEY); } /// A task that represents the asynchronous operation public async Task HandleEventAsync(EntityUpdatedEvent eventMessage) { await _staticCacheManager.RemoveByPrefixAsync(PICTURE_URL_PATTERN_KEY); } /// A task that represents the asynchronous operation public async Task HandleEventAsync(EntityDeletedEvent eventMessage) { await _staticCacheManager.RemoveByPrefixAsync(PICTURE_URL_PATTERN_KEY); } } }