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
|
|
|
|
{
|
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"]),
|
2021-07-02 11:35:20 +02:00
|
|
|
|
Buffer = (byte[])reader["buffer"]
|
2019-07-18 23:08:10 +02:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-02 11:35:20 +02:00
|
|
|
|
public async Task SetAsync(string key, ImageCacheItem cacheItem)
|
2019-07-18 23:08:10 +02:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2021-07-02 11:35:20 +02:00
|
|
|
|
using (var command = SetItemCommand(key, cacheItem.Expiration, cacheItem.Buffer))
|
2019-07-18 23:08:10 +02:00
|
|
|
|
{
|
|
|
|
|
|
await command.ExecuteNonQueryAsync();
|
|
|
|
|
|
}
|
2019-07-21 00:17:16 +02:00
|
|
|
|
|
2021-07-02 11:35:20 +02:00
|
|
|
|
//Debug.WriteLine("SQLiteCache.SetAsync(\"{0}\"): expires {1}", key, cacheItem.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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|