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.Runtime.InteropServices.WindowsRuntime;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Windows.Storage.Streams;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl.Caching
|
|
|
|
|
|
{
|
2019-07-21 00:17:16 +02:00
|
|
|
|
public partial class SQLiteCache : IImageCache
|
2019-07-18 23:08:10 +02:00
|
|
|
|
{
|
2019-07-21 00:17:16 +02:00
|
|
|
|
public async Task<ImageCacheItem> GetAsync(string key)
|
|
|
|
|
|
{
|
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
|
|
|
|
{
|
2019-07-22 19:47:57 +02:00
|
|
|
|
return new ImageCacheItem
|
2019-07-18 23:08:10 +02:00
|
|
|
|
{
|
|
|
|
|
|
Expiration = new DateTime((long)reader["expiration"]),
|
|
|
|
|
|
Buffer = ((byte[])reader["buffer"]).AsBuffer()
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2019-07-21 00:17:16 +02:00
|
|
|
|
Debug.WriteLine("SQLiteCache.GetAsync(\"{0}\"): {1}", 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task SetAsync(string key, IBuffer buffer, DateTime expiration)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2019-07-22 19:47:57 +02:00
|
|
|
|
using (var command = SetItemCommand(key, expiration, buffer?.ToArray()))
|
2019-07-18 23:08:10 +02:00
|
|
|
|
{
|
|
|
|
|
|
await command.ExecuteNonQueryAsync();
|
|
|
|
|
|
}
|
2019-07-21 00:17:16 +02:00
|
|
|
|
|
|
|
|
|
|
//Debug.WriteLine("SQLiteCache.SetAsync(\"{0}\"): expires {1}", key, expiration.ToLocalTime());
|
2019-07-18 23:08:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2019-07-21 00:17:16 +02:00
|
|
|
|
Debug.WriteLine("SQLiteCache.SetAsync(\"{0}\"): {1}", key, ex.Message);
|
2019-07-18 23:08:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|