2019-07-18 23:08:10 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2023-01-03 15:12:53 +01:00
|
|
|
|
// Copyright © 2023 Clemens Fischer
|
2019-07-18 23:08:10 +02:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl.Caching
|
|
|
|
|
|
{
|
2019-07-21 00:17:16 +02:00
|
|
|
|
public partial class SQLiteCache : IImageCache
|
2019-07-18 23:08:10 +02:00
|
|
|
|
{
|
2021-07-02 15:57:01 +02:00
|
|
|
|
public async Task<Tuple<byte[], DateTime>> GetAsync(string key)
|
2019-07-21 00:17:16 +02:00
|
|
|
|
{
|
2019-07-18 23:08:10 +02:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2019-07-21 00:17:16 +02:00
|
|
|
|
using (var command = GetItemCommand(key))
|
2019-07-18 23:08:10 +02:00
|
|
|
|
{
|
|
|
|
|
|
var reader = await command.ExecuteReaderAsync();
|
|
|
|
|
|
|
2019-07-21 00:17:16 +02:00
|
|
|
|
if (await reader.ReadAsync())
|
2019-07-18 23:08:10 +02:00
|
|
|
|
{
|
2021-07-02 15:57:01 +02:00
|
|
|
|
return Tuple.Create((byte[])reader["buffer"], new DateTime((long)reader["expiration"]));
|
2019-07-18 23:08:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2021-07-06 18:49:48 +02:00
|
|
|
|
Debug.WriteLine($"SQLiteCache.GetAsync({key}): {ex.Message}");
|
2019-07-18 23:08:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-22 19:47:57 +02:00
|
|
|
|
return null;
|
2019-07-18 23:08:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-02 15:57:01 +02:00
|
|
|
|
public async Task SetAsync(string key, byte[] buffer, DateTime expiration)
|
2019-07-18 23:08:10 +02:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2021-07-02 21:18:39 +02:00
|
|
|
|
using (var command = SetItemCommand(key, buffer, expiration))
|
2019-07-18 23:08:10 +02:00
|
|
|
|
{
|
|
|
|
|
|
await command.ExecuteNonQueryAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2021-07-06 18:49:48 +02:00
|
|
|
|
Debug.WriteLine($"SQLiteCache.SetAsync({key}): {ex.Message}");
|
2019-07-18 23:08:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|