XAML-Map-Control/SQLiteCache/UWP/SQLiteCache.UWP.cs

51 lines
1.4 KiB
C#
Raw Normal View History

2019-07-18 23:08:10 +02:00
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2021-01-13 21:19:27 +01:00
// © 2021 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)
{
Debug.WriteLine($"SQLiteCache.GetAsync({key}): {ex.Message}");
2019-07-18 23:08:10 +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)
{
Debug.WriteLine($"SQLiteCache.SetAsync({key}): {ex.Message}");
2019-07-18 23:08:10 +02:00
}
}
}
}