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

@ -21,6 +21,21 @@ namespace MapControl.Caching
private readonly FileDb fileDb = new FileDb() { AutoFlush = true };
public FileDbCache(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.fdb");
}
Open(path);
}
public void Dispose()
{
fileDb.Dispose();

View file

@ -3,31 +3,14 @@
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.IO;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Streams;
namespace MapControl.Caching
{
public partial class FileDbCache : IImageCache
{
public FileDbCache(StorageFolder folder, string fileName = "TileCache.fdb")
{
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));
}
Open(Path.Combine(folder.Path, fileName));
}
public Task<ImageCacheItem> GetAsync(string key)
{
return Task.Run(() =>

View file

@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.Caching;
@ -13,21 +12,6 @@ namespace MapControl.Caching
{
public partial class FileDbCache : ObjectCache
{
public FileDbCache(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.fdb");
}
Open(path);
}
public override string Name
{
get { return string.Empty; }