Files
SfeduSchedule/SfeduSchedule/Services/PluginCacheInvalidator.cs
T
serega404 c590a8a6c7
Create and publish a Docker image / Publish image (push) Successful in 1m53s
feat: добавил инвалидацию кэшей плагинов
2026-09-15 22:36:33 +03:00

33 lines
1.1 KiB
C#

using ModeusSchedule.Abstractions;
namespace SfeduSchedule.Services;
public sealed class PluginCacheInvalidator(
IEnumerable<IPlugin> plugins,
IServiceScopeFactory scopeFactory,
ILogger<PluginCacheInvalidator> logger)
{
public async Task InvalidateAsync(CancellationToken cancellationToken)
{
foreach (var plugin in plugins)
{
cancellationToken.ThrowIfCancellationRequested();
try
{
await using var scope = scopeFactory.CreateAsyncScope();
await plugin.InvalidateCacheAsync(scope.ServiceProvider, cancellationToken);
logger.LogInformation("Кэш плагина {PluginName} инвалидирован", plugin.Name);
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
throw;
}
catch (Exception ex)
{
logger.LogError(ex, "Не удалось инвалидировать кэш плагина {PluginName}", plugin.Name);
}
}
}
}