Cyclic clean

This commit is contained in:
ClemensFischer 2025-02-19 19:34:08 +01:00
parent df4b330d08
commit d31f522c52
2 changed files with 23 additions and 3 deletions

View file

@ -19,8 +19,14 @@ namespace MapControl.Caching
public sealed class SQLiteCache : IDistributedCache, IDisposable
{
private readonly SQLiteConnection connection;
private readonly Timer cleanTimer;
public SQLiteCache(string path)
: this(path, TimeSpan.FromHours(1))
{
}
public SQLiteCache(string path, TimeSpan autoCleanInterval)
{
if (string.IsNullOrEmpty(path))
{
@ -42,11 +48,15 @@ namespace MapControl.Caching
Debug.WriteLine($"{nameof(SQLiteCache)}: Opened database {path}");
Clean();
if (autoCleanInterval > TimeSpan.Zero)
{
cleanTimer = new Timer(_ => Clean(), null, TimeSpan.Zero, autoCleanInterval);
}
}
public void Dispose()
{
cleanTimer?.Dispose();
connection.Dispose();
}