diff --git a/MapControl/Shared/ImageFileCache.cs b/MapControl/Shared/ImageFileCache.cs index c5c3bf8b..751669ac 100644 --- a/MapControl/Shared/ImageFileCache.cs +++ b/MapControl/Shared/ImageFileCache.cs @@ -90,6 +90,8 @@ namespace MapControl.Caching var options = new DistributedCacheEntryOptions { AbsoluteExpiration = file.CreationTime }; memoryCache.Set(key, value, options); + + logger?.LogTrace("Read {name}", file.FullName); } } catch (Exception ex) @@ -123,6 +125,8 @@ namespace MapControl.Caching var options = new DistributedCacheEntryOptions { AbsoluteExpiration = file.CreationTime }; await memoryCache.SetAsync(key, value, options, token).ConfigureAwait(false); + + logger?.LogTrace("Read {name}", file.FullName); } } catch (Exception ex) @@ -155,6 +159,8 @@ namespace MapControl.Caching } SetExpiration(file, options); + + logger?.LogTrace("Wrote {name}", file.FullName); } } catch (Exception ex) @@ -184,6 +190,8 @@ namespace MapControl.Caching } SetExpiration(file, options); + + logger?.LogTrace("Wrote {name}", file.FullName); } } catch (Exception ex) diff --git a/MapControl/Shared/MapPanel.cs b/MapControl/Shared/MapPanel.cs index c23eaadb..d5a3cdc1 100644 --- a/MapControl/Shared/MapPanel.cs +++ b/MapControl/Shared/MapPanel.cs @@ -1,6 +1,4 @@ -using System; -using System.Diagnostics; -#if WPF +#if WPF using System.Windows; using System.Windows.Controls; using System.Windows.Media; diff --git a/MapControl/Shared/TileImageLoader.cs b/MapControl/Shared/TileImageLoader.cs index 599b48dd..64eb7f0c 100644 --- a/MapControl/Shared/TileImageLoader.cs +++ b/MapControl/Shared/TileImageLoader.cs @@ -8,6 +8,13 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; +#if WPF +using System.Windows.Media; +#elif UWP +using Windows.UI.Xaml.Media; +#elif WINUI +using Microsoft.UI.Xaml.Media; +#endif namespace MapControl { @@ -127,7 +134,9 @@ namespace MapControl if (string.IsNullOrEmpty(cacheName)) { - await LoadTileImage(tile, () => tileSource.LoadImageAsync(tile.Column, tile.Row, tile.ZoomLevel)).ConfigureAwait(false); + Task LoadImage() => tileSource.LoadImageAsync(tile.Column, tile.Row, tile.ZoomLevel); + + await LoadTileImage(tile, LoadImage).ConfigureAwait(false); } else { @@ -139,7 +148,9 @@ namespace MapControl if (buffer != null && buffer.Length > 0) { - await LoadTileImage(tile, () => tileSource.LoadImageAsync(buffer)).ConfigureAwait(false); + Task LoadImage() => tileSource.LoadImageAsync(buffer); + + await LoadTileImage(tile, LoadImage).ConfigureAwait(false); } } } @@ -160,7 +171,7 @@ namespace MapControl try { - buffer = await Cache.GetAsync(cacheKey); + buffer = await Cache.GetAsync(cacheKey).ConfigureAwait(false); } catch (Exception ex) { @@ -173,18 +184,20 @@ namespace MapControl if (response != null) { - buffer = response.Buffer; + buffer = response.Buffer ?? Array.Empty(); // cache even if null, when no tile available try { - var expiration = !response.MaxAge.HasValue ? DefaultCacheExpiration - : response.MaxAge.Value < MinCacheExpiration ? MinCacheExpiration - : response.MaxAge.Value > MaxCacheExpiration ? MaxCacheExpiration - : response.MaxAge.Value; + var options = new DistributedCacheEntryOptions + { + AbsoluteExpirationRelativeToNow = + !response.MaxAge.HasValue ? DefaultCacheExpiration + : response.MaxAge.Value < MinCacheExpiration ? MinCacheExpiration + : response.MaxAge.Value > MaxCacheExpiration ? MaxCacheExpiration + : response.MaxAge.Value + }; - await Cache.SetAsync(cacheKey, - buffer ?? Array.Empty(), // cache even if null, when no tile available - new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = expiration }); + await Cache.SetAsync(cacheKey, buffer, options).ConfigureAwait(false); } catch (Exception ex) {