diff --git a/MapControl/Shared/MapBase.cs b/MapControl/Shared/MapBase.cs index 43ded413..9c8a381f 100644 --- a/MapControl/Shared/MapBase.cs +++ b/MapControl/Shared/MapBase.cs @@ -34,7 +34,7 @@ namespace MapControl return Math.Log(scale * 360d * MapProjection.Wgs84MeterPerDegree / 256d, 2d); } - public static TimeSpan ImageFadeDuration { get; set; } = TimeSpan.FromSeconds(0.1); + public static TimeSpan ImageFadeDuration { get; set; } = TimeSpan.FromSeconds(0.2); public static readonly DependencyProperty AnimationDurationProperty = DependencyPropertyHelper.Register(nameof(AnimationDuration), TimeSpan.FromSeconds(0.3)); diff --git a/MapControl/Shared/TileImageLoader.cs b/MapControl/Shared/TileImageLoader.cs index cc560b68..d2147c39 100644 --- a/MapControl/Shared/TileImageLoader.cs +++ b/MapControl/Shared/TileImageLoader.cs @@ -188,41 +188,40 @@ namespace MapControl } var cacheKey = $"{cacheName}/{tile.ZoomLevel}/{tile.Column}/{tile.Row}{extension}"; + byte[] buffer = null; try { - var cachedBuffer = await Cache.GetAsync(cacheKey).ConfigureAwait(false); - - if (cachedBuffer != null) - { - return cachedBuffer; - } + buffer = await Cache.GetAsync(cacheKey).ConfigureAwait(false); } catch (Exception ex) { Logger?.LogError(ex, "Cache.GetAsync({cacheKey})", cacheKey); } - (var buffer, var maxAge) = await ImageLoader.GetHttpResponseAsync(uri).ConfigureAwait(false); - - if (buffer != null) + if (buffer == null) { - try - { - var options = new DistributedCacheEntryOptions - { - AbsoluteExpirationRelativeToNow = - !maxAge.HasValue ? DefaultCacheExpiration - : maxAge.Value < MinCacheExpiration ? MinCacheExpiration - : maxAge.Value > MaxCacheExpiration ? MaxCacheExpiration - : maxAge.Value - }; + (buffer, var maxAge) = await ImageLoader.GetHttpResponseAsync(uri).ConfigureAwait(false); - await Cache.SetAsync(cacheKey, buffer, options).ConfigureAwait(false); - } - catch (Exception ex) + if (buffer != null) { - Logger?.LogError(ex, "Cache.SetAsync({cacheKey})", cacheKey); + try + { + var options = new DistributedCacheEntryOptions + { + AbsoluteExpirationRelativeToNow = + !maxAge.HasValue ? DefaultCacheExpiration + : maxAge.Value < MinCacheExpiration ? MinCacheExpiration + : maxAge.Value > MaxCacheExpiration ? MaxCacheExpiration + : maxAge.Value + }; + + await Cache.SetAsync(cacheKey, buffer, options).ConfigureAwait(false); + } + catch (Exception ex) + { + Logger?.LogError(ex, "Cache.SetAsync({cacheKey})", cacheKey); + } } }