33 lines
1.1 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|
|
}
|