From 768c01316996440e4f88734a902ba4da44acbfa5 Mon Sep 17 00:00:00 2001 From: Clemens Date: Tue, 7 Jan 2020 11:10:16 +0100 Subject: [PATCH] Update ImageFileCache.WPF.cs Fixed reading cache expiration --- MapControl/WPF/ImageFileCache.WPF.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/MapControl/WPF/ImageFileCache.WPF.cs b/MapControl/WPF/ImageFileCache.WPF.cs index f2015da9..137eabaf 100644 --- a/MapControl/WPF/ImageFileCache.WPF.cs +++ b/MapControl/WPF/ImageFileCache.WPF.cs @@ -108,23 +108,23 @@ namespace MapControl.Caching try { var buffer = File.ReadAllBytes(path); - var expiration = DateTime.MinValue; if (buffer.Length > 16 && Encoding.ASCII.GetString(buffer, buffer.Length - 16, 8) == "EXPIRES:") { - expiration = new DateTime(BitConverter.ToInt64(buffer, buffer.Length - 8), DateTimeKind.Utc); + var expiration = new DateTime(BitConverter.ToInt64(buffer, buffer.Length - 8), DateTimeKind.Utc); + Array.Resize(ref buffer, buffer.Length - 16); + + imageCacheItem = new ImageCacheItem + { + Buffer = buffer, + Expiration = expiration + }; + + memoryCache.Set(key, imageCacheItem, new CacheItemPolicy { AbsoluteExpiration = expiration }); + + //Debug.WriteLine("ImageFileCache: Reading {0}, Expires {1}", path, imageCacheItem.Expiration.ToLocalTime()); } - - imageCacheItem = new ImageCacheItem - { - Buffer = buffer, - Expiration = expiration - }; - - memoryCache.Set(key, imageCacheItem, new CacheItemPolicy { AbsoluteExpiration = expiration }); - - //Debug.WriteLine("ImageFileCache: Reading {0}, Expires {1}", path, imageCacheItem.Expiration.ToLocalTime()); } catch (Exception ex) {