using Nop.Core.Caching; using Nop.Core.Domain.Configuration; using Nop.Core.Events; using Nop.Services.Events; namespace Nop.Plugin.Widgets.NivoSlider.Infrastructure.Cache; /// /// Model cache event consumer (used for caching of presentation layer models) /// public class ModelCacheEventConsumer : IConsumer>, IConsumer>, IConsumer> { /// /// Key for caching /// /// /// {0} : picture id /// {1} : connection type (http/https) /// public static CacheKey PICTURE_URL_MODEL_KEY = new("Nop.plugins.widgets.nivoslider.pictureurl-{0}-{1}", PICTURE_URL_PATTERN_KEY); public const string PICTURE_URL_PATTERN_KEY = "Nop.plugins.widgets.nivoslider"; protected 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); } }