mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-01-13 12:10:07 +01:00
Cyclic clean
This commit is contained in:
parent
df4b330d08
commit
d31f522c52
|
|
@ -23,8 +23,14 @@ namespace MapControl.Caching
|
|||
private const string expiresField = "Expires";
|
||||
|
||||
private readonly FileDb fileDb = new FileDb { AutoFlush = true };
|
||||
private readonly Timer cleanTimer;
|
||||
|
||||
public FileDbCache(string path)
|
||||
: this(path, TimeSpan.FromHours(1))
|
||||
{
|
||||
}
|
||||
|
||||
public FileDbCache(string path, TimeSpan autoCleanInterval)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
|
|
@ -40,8 +46,6 @@ namespace MapControl.Caching
|
|||
{
|
||||
fileDb.Open(path);
|
||||
Debug.WriteLine($"{nameof(FileDbCache)}: Opened database {path}");
|
||||
|
||||
Clean();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -63,10 +67,16 @@ namespace MapControl.Caching
|
|||
|
||||
Debug.WriteLine($"{nameof(FileDbCache)}: Created database {path}");
|
||||
}
|
||||
|
||||
if (autoCleanInterval > TimeSpan.Zero)
|
||||
{
|
||||
cleanTimer = new Timer(_ => Clean(), null, TimeSpan.Zero, autoCleanInterval);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
cleanTimer?.Dispose();
|
||||
fileDb.Dispose();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue