Version 4.13.1 Cache "no tile" responses.

This commit is contained in:
ClemensF 2019-07-22 19:47:57 +02:00
parent 576dd8e8e7
commit 219171381f
27 changed files with 200 additions and 338 deletions

View file

@ -47,6 +47,23 @@ namespace MapControl.Caching
command.Parameters.AddWithValue("@exp", DateTime.UtcNow.Ticks);
command.ExecuteNonQuery();
}
#if DEBUG
using (var command = new SQLiteCommand("select changes()", connection))
{
var deleted = (long)command.ExecuteScalar();
if (deleted > 0)
{
Debug.WriteLine("SQLiteCache: Deleted {0} expired items.", deleted);
}
}
#endif
}
private SQLiteCommand RemoveItemCommand(string key)
{
var command = new SQLiteCommand("delete from items where key = @key", connection);
command.Parameters.AddWithValue("@key", key);
return command;
}
private SQLiteCommand GetItemCommand(string key)
@ -61,14 +78,7 @@ namespace MapControl.Caching
var command = new SQLiteCommand("insert or replace into items (key, expiration, buffer) values (@key, @exp, @buf)", connection);
command.Parameters.AddWithValue("@key", key);
command.Parameters.AddWithValue("@exp", expiration.Ticks);
command.Parameters.AddWithValue("@buf", buffer);
return command;
}
private SQLiteCommand RemoveItemCommand(string key)
{
var command = new SQLiteCommand("delete from items where key = @key", connection);
command.Parameters.AddWithValue("@key", key);
command.Parameters.AddWithValue("@buf", buffer ?? new byte[0]);
return command;
}
}

View file

@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © 2019 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("4.13.0")]
[assembly: AssemblyFileVersion("4.13.0")]
[assembly: AssemblyVersion("4.13.1")]
[assembly: AssemblyFileVersion("4.13.1")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -26,7 +26,7 @@ namespace MapControl.Caching
if (string.IsNullOrEmpty(fileName))
{
throw new ArgumentNullException("The parameter fileName must not be null.");
throw new ArgumentException("The parameter fileName must not be null or empty.");
}
connection = Open(Path.Combine(folder.Path, fileName));
@ -36,13 +36,6 @@ namespace MapControl.Caching
public async Task<ImageCacheItem> GetAsync(string key)
{
if (key == null)
{
throw new ArgumentNullException("The parameter key must not be null.");
}
ImageCacheItem imageCacheItem = null;
try
{
using (var command = GetItemCommand(key))
@ -51,7 +44,7 @@ namespace MapControl.Caching
if (await reader.ReadAsync())
{
imageCacheItem = new ImageCacheItem
return new ImageCacheItem
{
Expiration = new DateTime((long)reader["expiration"]),
Buffer = ((byte[])reader["buffer"]).AsBuffer()
@ -64,24 +57,14 @@ namespace MapControl.Caching
Debug.WriteLine("SQLiteCache.GetAsync(\"{0}\"): {1}", key, ex.Message);
}
return imageCacheItem;
return null;
}
public async Task SetAsync(string key, IBuffer buffer, DateTime expiration)
{
if (key == null)
{
throw new ArgumentNullException("The parameter key must not be null.");
}
if (buffer == null)
{
throw new ArgumentNullException("The parameter buffer must not be null.");
}
try
{
using (var command = SetItemCommand(key, expiration, buffer.ToArray()))
using (var command = SetItemCommand(key, expiration, buffer?.ToArray()))
{
await command.ExecuteNonQueryAsync();
}

View file

@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © 2019 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("4.13.0")]
[assembly: AssemblyFileVersion("4.13.0")]
[assembly: AssemblyVersion("4.13.1")]
[assembly: AssemblyFileVersion("4.13.1")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -121,8 +121,6 @@ namespace MapControl.Caching
throw new ArgumentNullException("The parameter key must not be null.");
}
ImageCacheItem imageCacheItem = null;
try
{
using (var command = GetItemCommand(key))
@ -131,7 +129,7 @@ namespace MapControl.Caching
if (reader.Read())
{
imageCacheItem = new ImageCacheItem
return new ImageCacheItem
{
Expiration = new DateTime((long)reader["expiration"]),
Buffer = (byte[])reader["buffer"]
@ -144,7 +142,7 @@ namespace MapControl.Caching
Debug.WriteLine("SQLiteCache.Get(\"{0}\"): {1}", key, ex.Message);
}
return imageCacheItem;
return null;
}
public override CacheItem GetCacheItem(string key, string regionName = null)
@ -173,9 +171,9 @@ namespace MapControl.Caching
var imageCacheItem = value as ImageCacheItem;
if (imageCacheItem == null || imageCacheItem.Buffer == null || imageCacheItem.Buffer.Length == 0)
if (imageCacheItem == null)
{
throw new ArgumentException("The parameter value must be an ImageCacheItem with a non-empty Buffer.");
throw new ArgumentException("The parameter value must be a MapControl.Caching.ImageCacheItem instance.");
}
try