加权LRU缓存。这种方法有名称吗?

时间:2017-10-19 20:50:27

标签: algorithm caching data-structures

假设我有一个应用程序尝试将字符串与int相关联。有许多字符串,我想保留已经发生的前N个列表。

例如,说字符串看起来像这样:

item 0 = "Foo"
item 1 = "Foo"
item 2 = "Boo"
item 3 = "Boo"
item 4 = "Bar"
item 5 = "Sar"

假设我的缓存的上限为3.这就是我希望它的表现方式:

item 0 = TryGet "Foo" - Add. "Foo" occurrences = 1
item 1 = TryGet "Foo" - return. "Foo" occurrences = 2
item 2 = TryGet "Boo" - Add. "Boo" occurrences = 1
item 3 = TryGet "Boo" - return. "Boo" occurrences = 2
item 4 = TryGet "Bar" - Add. "Bar" occurrences = 1
item 5 = TryGet "Sar" - At capacity. Remove elem with lowest occurrences, "Bar". Add "Sar"

因此,每个当前缓存项都会获得权重,并且在达到容量时发现新项目时,我们会抛出具有最少get事件数的元素。这种缓存算法有名称吗?

编辑: 我一直在寻找Least-Frequently Used

https://en.wikipedia.org/wiki/Cache_replacement_policies#Least-Frequently_Used_.28LFU.29

1 个答案:

答案 0 :(得分:0)

我一直在寻找Least-Frequently Used