◆ LruCache()
27 {
28 this.capacity = capacity;
29 }
◆ Add()
47 {
48 if (cacheMap.Count >= capacity)
49 {
50 var oldest = lruList.First;
51 if (oldest != null)
52 {
53 lruList.RemoveFirst();
54 cacheMap.Remove(oldest.Value.key);
55 }
56 }
57
58 if (cacheMap.ContainsKey(key))
59 {
60 lruList.Remove(cacheMap[key]);
61 }
62
63 var newNode = new LinkedListNode<(Info key, TValue value)>((key, value));
64 lruList.AddLast(newNode);
65 cacheMap[key] = newNode;
66 }
◆ Dispose()
68 {
69 foreach (LinkedListNode<(Info key, TValue value)> item in cacheMap.Values)
70 {
71 lruList.Remove(item);
72 }
73 }
◆ Get()
32 {
33 foreach (LinkedListNode<(Info key, TValue value)> item in cacheMap.Values)
34 {
35 Info k = item.Value.key;
36 if(k.Coordinate == key.Coordinate && k.Index == key.Index)
37 {
38 lruList.Remove(item);
39 lruList.AddLast(item);
40 return item.Value.value;
41 }
42 }
43 return default(TValue);
44 }
The documentation for this class was generated from the following file: