Move Image Cache filtering earlier

This commit is contained in:
弘韬 张 2020-11-15 21:03:39 +08:00
parent 4dd4cdafbf
commit b1dd7b4181

View file

@ -26,7 +26,7 @@ namespace Flow.Launcher.Infrastructure.Image
private const int MaxCached = 50;
public ConcurrentDictionary<string, ImageUsage> Data { get; private set; } = new ConcurrentDictionary<string, ImageUsage>();
private const int permissibleFactor = 2;
public void Initialization(Dictionary<string, int> usage)
{
foreach (var key in usage.Keys)
@ -65,15 +65,13 @@ namespace Flow.Launcher.Infrastructure.Image
if (Data.Count > permissibleFactor * MaxCached)
{
// To delete the images from the data dictionary based on the resizing of the Usage Dictionary.
foreach (var key in Data.Where(x => x.Key != Constant.MissingImgIcon)
foreach (var key in Data
.Where(x => x.Key != Constant.MissingImgIcon
&& x.Key != Constant.ErrorIcon
&& x.Key != Constant.DefaultIcon)
.OrderBy(x => x.Value.usage).Take(Data.Count - MaxCached).Select(x => x.Key))
{
if (!(key.Equals(Constant.ErrorIcon) || key.Equals(Constant.DefaultIcon)))
{
Data.TryRemove(key, out _);
}
Data.TryRemove(key, out _);
}
}
}