mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Move ImageLoader to Wox.Infrastructure, part 1
This commit is contained in:
35
Wox.Infrastructure/Image/ImageCache.cs
Normal file
35
Wox.Infrastructure/Image/ImageCache.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Wox.Infrastructure.Storage;
|
||||
|
||||
namespace Wox.ImageLoader
|
||||
{
|
||||
[Serializable]
|
||||
public class ImageCache
|
||||
{
|
||||
private const int MaxCached = 200;
|
||||
public ConcurrentDictionary<string, int> TopUsedImages = new ConcurrentDictionary<string, int>();
|
||||
|
||||
public void Add(string path)
|
||||
{
|
||||
if (TopUsedImages.ContainsKey(path))
|
||||
{
|
||||
TopUsedImages[path] = TopUsedImages[path] + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
TopUsedImages[path] = 1;
|
||||
}
|
||||
|
||||
if (TopUsedImages.Count > MaxCached)
|
||||
{
|
||||
var images = TopUsedImages.OrderByDescending(o => o.Value)
|
||||
.Take(MaxCached)
|
||||
.ToDictionary(i => i.Key, i => i.Value);
|
||||
TopUsedImages = new ConcurrentDictionary<string, int>(images);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user