mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-15 12:09:18 +08:00
8d10c9aa41
1. part of #389 2. huge refactoring
48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Wox.Infrastructure.Storage;
|
|
|
|
namespace Wox.ImageLoader
|
|
{
|
|
[Serializable]
|
|
public class ImageCache
|
|
{
|
|
private int counter;
|
|
private const int maxCached = 200;
|
|
public Dictionary<string, int> TopUsedImages = new Dictionary<string, int>();
|
|
|
|
public void Add(string path)
|
|
{
|
|
if (TopUsedImages.ContainsKey(path))
|
|
{
|
|
TopUsedImages[path] = TopUsedImages[path] + 1 ;
|
|
}
|
|
else
|
|
{
|
|
TopUsedImages.Add(path, 1);
|
|
}
|
|
|
|
if (TopUsedImages.Count > maxCached)
|
|
{
|
|
TopUsedImages = TopUsedImages.OrderByDescending(o => o.Value)
|
|
.Take(maxCached)
|
|
.ToDictionary(i => i.Key, i => i.Value);
|
|
}
|
|
|
|
if (++counter == 30)
|
|
{
|
|
counter = 0;
|
|
}
|
|
}
|
|
|
|
public void Remove(string path)
|
|
{
|
|
if (TopUsedImages.ContainsKey(path))
|
|
{
|
|
TopUsedImages.Remove(path);
|
|
}
|
|
}
|
|
}
|
|
}
|