mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 14:37:01 +00:00
Clean/CleanAsync in cache implementations
This commit is contained in:
parent
7ab95c3bed
commit
cdb7d4af15
3 changed files with 76 additions and 49 deletions
|
|
@ -50,25 +50,6 @@ namespace MapControl.Caching
|
|||
connection.Dispose();
|
||||
}
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var command = new SQLiteCommand("delete from items where expiration < @exp", connection))
|
||||
{
|
||||
command.Parameters.AddWithValue("@exp", DateTimeOffset.UtcNow.Ticks);
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
#if DEBUG
|
||||
using (var command = new SQLiteCommand("select changes()", connection))
|
||||
{
|
||||
var deleted = (long)command.ExecuteScalar();
|
||||
if (deleted > 0)
|
||||
{
|
||||
Debug.WriteLine($"SQLiteCache: Deleted {deleted} expired items");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public byte[] Get(string key)
|
||||
{
|
||||
CheckArgument(key);
|
||||
|
|
@ -201,6 +182,44 @@ namespace MapControl.Caching
|
|||
}
|
||||
}
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var command = new SQLiteCommand("delete from items where expiration < @exp", connection))
|
||||
{
|
||||
command.Parameters.AddWithValue("@exp", DateTimeOffset.UtcNow.Ticks);
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
#if DEBUG
|
||||
using (var command = new SQLiteCommand("select changes()", connection))
|
||||
{
|
||||
var deleted = (long)command.ExecuteScalar();
|
||||
if (deleted > 0)
|
||||
{
|
||||
Debug.WriteLine($"SQLiteCache: Deleted {deleted} expired items");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public async Task CleanAsync()
|
||||
{
|
||||
using (var command = new SQLiteCommand("delete from items where expiration < @exp", connection))
|
||||
{
|
||||
command.Parameters.AddWithValue("@exp", DateTimeOffset.UtcNow.Ticks);
|
||||
await command.ExecuteNonQueryAsync();
|
||||
}
|
||||
#if DEBUG
|
||||
using (var command = new SQLiteCommand("select changes()", connection))
|
||||
{
|
||||
var deleted = (long)await command.ExecuteScalarAsync();
|
||||
if (deleted > 0)
|
||||
{
|
||||
Debug.WriteLine($"SQLiteCache: Deleted {deleted} expired items");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private SQLiteCommand GetItemCommand(string key)
|
||||
{
|
||||
var command = new SQLiteCommand("select expiration, buffer from items where key = @key", connection);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue