|
|
@@ -32,33 +32,27 @@ static class StaticImageCache
|
|
|
if (isPathRooted)
|
|
|
return LoadImage(filePath, false);
|
|
|
|
|
|
-
|
|
|
// check file size
|
|
|
var fileInfo = new FileInfo(filePath);
|
|
|
|
|
|
if (fileInfo.Length > MaxItemSize)
|
|
|
return LoadImage(filePath, false);
|
|
|
-
|
|
|
|
|
|
// check if the image is already in cache
|
|
|
if (Items.TryGetValue(filePath, out var cacheItem))
|
|
|
return cacheItem;
|
|
|
|
|
|
-
|
|
|
// if cache is larger than expected, the usage might be different from loading static images
|
|
|
if (!CacheIsEnabled)
|
|
|
return LoadImage(filePath, false);
|
|
|
|
|
|
-
|
|
|
// create new cache item and add it to the cache
|
|
|
var image = LoadImage(filePath, true);
|
|
|
Items.TryAdd(filePath, image);
|
|
|
|
|
|
-
|
|
|
// check cache size
|
|
|
CacheIsEnabled = Items.Values.Sum(x => x.SkImage.EncodedDataSize) < MaxCacheSize;
|
|
|
|
|
|
-
|
|
|
// return cached value
|
|
|
return image;
|
|
|
}
|