diff --git a/MapControl/UWP/ImageFileCache.UWP.cs b/MapControl/UWP/ImageFileCache.UWP.cs index bc28b68f..fd4f0cdc 100644 --- a/MapControl/UWP/ImageFileCache.UWP.cs +++ b/MapControl/UWP/ImageFileCache.UWP.cs @@ -45,19 +45,19 @@ namespace MapControl.Caching public async Task SetAsync(string key, IBuffer buffer, DateTime expiration) { - string path; + var path = GetPath(key); - if (buffer != null && buffer.Length > 0 && (path = GetPath(key)) != null) + if (buffer != null && buffer.Length > 0 && path != null) { try { Directory.CreateDirectory(Path.GetDirectoryName(path)); - using (var stream = File.Create(path).AsOutputStream()) + using (var stream = File.Create(path)) { - await stream.WriteAsync(buffer); - await stream.WriteAsync(Encoding.ASCII.GetBytes(expiresTag).AsBuffer()); - await stream.WriteAsync(BitConverter.GetBytes(expiration.Ticks).AsBuffer()); + await stream.AsOutputStream().WriteAsync(buffer); + await stream.WriteAsync(Encoding.ASCII.GetBytes(expiresTag), 0, 8); + await stream.WriteAsync(BitConverter.GetBytes(expiration.Ticks), 0, 8); } //Debug.WriteLine("ImageFileCache: Wrote {0}, Expires {1}", path, expiration.ToLocalTime()); diff --git a/MapControl/WPF/ImageFileCache.WPF.cs b/MapControl/WPF/ImageFileCache.WPF.cs index d32a9aa3..f41694bb 100644 --- a/MapControl/WPF/ImageFileCache.WPF.cs +++ b/MapControl/WPF/ImageFileCache.WPF.cs @@ -160,11 +160,10 @@ namespace MapControl.Caching memoryCache.Set(key, imageCacheItem, policy); - string path; + var buffer = imageCacheItem.Buffer; + var path = GetPath(key); - if (imageCacheItem.Buffer != null && - imageCacheItem.Buffer.Length > 0 && - (path = GetPath(key)) != null) + if (buffer != null && buffer.Length > 0 && path != null) { try { @@ -172,7 +171,7 @@ namespace MapControl.Caching using (var stream = File.Create(path)) { - stream.Write(imageCacheItem.Buffer, 0, imageCacheItem.Buffer.Length); + stream.Write(buffer, 0, buffer.Length); stream.Write(Encoding.ASCII.GetBytes(expiresTag), 0, 8); stream.Write(BitConverter.GetBytes(imageCacheItem.Expiration.Ticks), 0, 8); }