Unified cache implementations

This commit is contained in:
Clemens 2021-06-30 14:17:54 +02:00
parent 3dc3db1d79
commit 8cb20f0544
8 changed files with 37 additions and 87 deletions

View file

@ -5,6 +5,7 @@
using System;
using System.Data.SQLite;
using System.Diagnostics;
using System.IO;
namespace MapControl.Caching
{
@ -15,6 +16,23 @@ namespace MapControl.Caching
{
private readonly SQLiteConnection connection;
public SQLiteCache(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentException("The path argument must not be null or empty.", nameof(path));
}
if (string.IsNullOrEmpty(Path.GetExtension(path)))
{
path = Path.Combine(path, "TileCache.sqlite");
}
connection = Open(Path.GetFullPath(path));
Clean();
}
private static SQLiteConnection Open(string path)
{
var connection = new SQLiteConnection("Data Source=" + path);

View file

@ -4,36 +4,14 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Streams;
namespace MapControl.Caching
{
/// <summary>
/// IImageCache implementation based on SqLite.
/// </summary>
public partial class SQLiteCache : IImageCache
{
public SQLiteCache(StorageFolder folder, string fileName = "TileCache.sqlite")
{
if (folder == null)
{
throw new ArgumentNullException(nameof(folder));
}
if (string.IsNullOrEmpty(fileName))
{
throw new ArgumentException("The fileName argument must not be null or empty.", nameof(fileName));
}
connection = Open(Path.Combine(folder.Path, fileName));
Clean();
}
public async Task<ImageCacheItem> GetAsync(string key)
{
try

View file

@ -6,34 +6,13 @@ using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.Caching;
namespace MapControl.Caching
{
/// <summary>
/// ObjectCache implementation based on SqLite.
/// </summary>
public partial class SQLiteCache : ObjectCache
{
public SQLiteCache(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentException("The path argument must not be null or empty.", nameof(path));
}
if (string.IsNullOrEmpty(Path.GetExtension(path)))
{
path = Path.Combine(path, "TileCache.sqlite");
}
connection = Open(Path.GetFullPath(path));
Clean();
}
public override string Name
{
get { return string.Empty; }