From d27562a8897d7f3e34767338222b457421346506 Mon Sep 17 00:00:00 2001 From: Flaminel Date: Sun, 23 Feb 2025 10:59:43 +0200 Subject: [PATCH] explicit dispose and clean on some objects --- code/Executable/DependencyInjection/MainDI.cs | 4 +++- .../Verticals/ContentBlocker/BlocklistProvider.cs | 2 +- .../Verticals/Files/UnixHardLinkFileService.cs | 7 ++++++- .../Verticals/Files/WindowsHardLinkFileService.cs | 7 ++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/code/Executable/DependencyInjection/MainDI.cs b/code/Executable/DependencyInjection/MainDI.cs index e638ecc..5eda28a 100644 --- a/code/Executable/DependencyInjection/MainDI.cs +++ b/code/Executable/DependencyInjection/MainDI.cs @@ -17,7 +17,9 @@ public static class MainDI .AddLogging(builder => builder.ClearProviders().AddConsole()) .AddHttpClients(configuration) .AddConfiguration(configuration) - .AddMemoryCache() + .AddMemoryCache(options => { + options.ExpirationScanFrequency = TimeSpan.FromMinutes(1); + }) .AddServices() .AddQuartzServices(configuration) .AddNotifications(configuration) diff --git a/code/Infrastructure/Verticals/ContentBlocker/BlocklistProvider.cs b/code/Infrastructure/Verticals/ContentBlocker/BlocklistProvider.cs index 90d91e3..46a4ebd 100644 --- a/code/Infrastructure/Verticals/ContentBlocker/BlocklistProvider.cs +++ b/code/Infrastructure/Verticals/ContentBlocker/BlocklistProvider.cs @@ -43,7 +43,7 @@ public sealed class BlocklistProvider { if (_initialized) { - _logger.LogDebug("blocklists already loaded"); + _logger.LogTrace("blocklists already loaded"); return; } diff --git a/code/Infrastructure/Verticals/Files/UnixHardLinkFileService.cs b/code/Infrastructure/Verticals/Files/UnixHardLinkFileService.cs index ddd0026..3af570c 100644 --- a/code/Infrastructure/Verticals/Files/UnixHardLinkFileService.cs +++ b/code/Infrastructure/Verticals/Files/UnixHardLinkFileService.cs @@ -4,7 +4,7 @@ using Mono.Unix.Native; namespace Infrastructure.Verticals.Files; -public class UnixHardLinkFileService : IHardLinkFileService +public class UnixHardLinkFileService : IHardLinkFileService, IDisposable { private readonly ILogger _logger; private readonly ConcurrentDictionary _inodeCounts = new(); @@ -83,4 +83,9 @@ public class UnixHardLinkFileService : IHardLinkFileService throw; } } + + public void Dispose() + { + _inodeCounts.Clear(); + } } \ No newline at end of file diff --git a/code/Infrastructure/Verticals/Files/WindowsHardLinkFileService.cs b/code/Infrastructure/Verticals/Files/WindowsHardLinkFileService.cs index 47ff71e..5fd9e97 100644 --- a/code/Infrastructure/Verticals/Files/WindowsHardLinkFileService.cs +++ b/code/Infrastructure/Verticals/Files/WindowsHardLinkFileService.cs @@ -5,7 +5,7 @@ using Microsoft.Win32.SafeHandles; namespace Infrastructure.Verticals.Files; -public class WindowsHardLinkFileService : IHardLinkFileService +public class WindowsHardLinkFileService : IHardLinkFileService, IDisposable { private readonly ILogger _logger; private readonly ConcurrentDictionary _fileIndexCounts = new(); @@ -110,4 +110,9 @@ public class WindowsHardLinkFileService : IHardLinkFileService public uint FileIndexHigh; public uint FileIndexLow; } + + public void Dispose() + { + _fileIndexCounts.Clear(); + } } \ No newline at end of file