Minor changes

This commit is contained in:
ClemensFischer 2025-12-22 17:23:15 +01:00
parent 2b3a8606c0
commit 7cdbca9c8c
2 changed files with 23 additions and 24 deletions

View file

@ -34,7 +34,7 @@ namespace MapControl
return Math.Log(scale * 360d * MapProjection.Wgs84MeterPerDegree / 256d, 2d); 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 = public static readonly DependencyProperty AnimationDurationProperty =
DependencyPropertyHelper.Register<MapBase, TimeSpan>(nameof(AnimationDuration), TimeSpan.FromSeconds(0.3)); DependencyPropertyHelper.Register<MapBase, TimeSpan>(nameof(AnimationDuration), TimeSpan.FromSeconds(0.3));

View file

@ -188,41 +188,40 @@ namespace MapControl
} }
var cacheKey = $"{cacheName}/{tile.ZoomLevel}/{tile.Column}/{tile.Row}{extension}"; var cacheKey = $"{cacheName}/{tile.ZoomLevel}/{tile.Column}/{tile.Row}{extension}";
byte[] buffer = null;
try try
{ {
var cachedBuffer = await Cache.GetAsync(cacheKey).ConfigureAwait(false); buffer = await Cache.GetAsync(cacheKey).ConfigureAwait(false);
if (cachedBuffer != null)
{
return cachedBuffer;
}
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger?.LogError(ex, "Cache.GetAsync({cacheKey})", cacheKey); Logger?.LogError(ex, "Cache.GetAsync({cacheKey})", cacheKey);
} }
(var buffer, var maxAge) = await ImageLoader.GetHttpResponseAsync(uri).ConfigureAwait(false); if (buffer == null)
if (buffer != null)
{ {
try (buffer, var maxAge) = await ImageLoader.GetHttpResponseAsync(uri).ConfigureAwait(false);
{
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); if (buffer != null)
}
catch (Exception ex)
{ {
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);
}
} }
} }