using Nop.Core.Caching; using Nop.Core.Domain.Configuration; using Nop.Core.Events; using Nop.Services.Events; namespace Nop.Plugin.Widgets.Swiper.Infrastructure.Cache; /// /// Model cache event consumer (used for caching of presentation layer models) /// public class ModelCacheEventConsumer : IConsumer>, IConsumer>, IConsumer> { #region Fields private readonly IStaticCacheManager _staticCacheManager; #endregion #region Ctor public ModelCacheEventConsumer(IStaticCacheManager staticCacheManager) { _staticCacheManager = staticCacheManager; } #endregion #region Methods /// /// Handle entity inserted event /// /// Event message /// A task that represents the asynchronous operation public async Task HandleEventAsync(EntityInsertedEvent eventMessage) { await _staticCacheManager.RemoveByPrefixAsync(PictureUrlPrefix); } /// /// Handle entity updated event /// /// Event message /// A task that represents the asynchronous operation public async Task HandleEventAsync(EntityUpdatedEvent eventMessage) { await _staticCacheManager.RemoveByPrefixAsync(PictureUrlPrefix); } /// /// Handle entity deleted event /// /// Event message /// A task that represents the asynchronous operation public async Task HandleEventAsync(EntityDeletedEvent eventMessage) { await _staticCacheManager.RemoveByPrefixAsync(PictureUrlPrefix); } #endregion #region Properties /// /// Gets a key pattern to clear cache /// protected static string PictureUrlPrefix => "Nop.plugins.widgets.swiper"; /// /// Key for caching /// /// /// {0} : picture id /// {1} : secured /// public static CacheKey PictureUrlModelKey => new("Nop.plugins.widgets.swiper.pictureurl-{0}-{1}", PictureUrlPrefix); #endregion }