using Erp.Languages.Entities; using System; using System.Threading.Tasks; using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Entities.Events.Distributed; using Volo.Abp.Domain.Repositories; using Volo.Abp.EventBus.Distributed; namespace Erp.Languages; public class LanguageTextCacheItemInvalidatorDistributed : IDistributedEventHandler>, IDistributedEventHandler>, IDistributedEventHandler>, ITransientDependency { private readonly IRepository languageTextRepository; private readonly IDistributedCache cache; public LanguageTextCacheItemInvalidatorDistributed( IRepository languageTextRepository, IDistributedCache cache) { this.languageTextRepository = languageTextRepository; this.cache = cache; } public async Task HandleEventAsync(EntityCreatedEto eventData) { await InvalidateCacheAsync(eventData.Entity); } public async Task HandleEventAsync(EntityUpdatedEto eventData) { await InvalidateCacheAsync(eventData.Entity); } public async Task HandleEventAsync(EntityDeletedEto eventData) { await InvalidateCacheAsync(eventData.Entity); } private async Task InvalidateCacheAsync(LanguageTextEto eventData) { var key = LanguageTextCacheItem.CalculateCacheKey(eventData.ResourceName, eventData.CultureName); await cache.RemoveAsync(key); } } public class LanguageTextEto { public string CultureName { get; set; } public string ResourceName { get; set; } } // For distributed event bus //private void ConfigureDistributedEventBus() //{ // Configure(options => // { // //Enable for all entities // //options.AutoEventSelectors.AddAll(); // //Enable for a single entity // options.AutoEventSelectors.Add(); // options.EtoMappings.Add(); // //Enable for all entities in a namespace (and child namespaces) // //options.AutoEventSelectors.AddNamespace("MyProject.Products"); // //Custom predicate expression that should return true to select a type // //options.AutoEventSelectors.Add(type => type.Namespace.StartsWith("MyProject.")); // }); //}