File tree Expand file tree Collapse file tree 3 files changed +13
-3
lines changed Expand file tree Collapse file tree 3 files changed +13
-3
lines changed Original file line number Diff line number Diff line change 5
5
)
6
6
7
7
// Cache is used a FIFO (First in first out) cache replacement policy.
8
+ //
8
9
// In FIFO the item that enter the cache first is evicted first
9
10
// w/o any regard of how often or how many times it was accessed before.
10
11
type Cache [K comparable , V any ] struct {
@@ -38,7 +39,7 @@ func WithCapacity(cap int) Option {
38
39
}
39
40
}
40
41
41
- // NewCache creates a new cache.
42
+ // NewCache creates a new FIFO cache whose capacity is the default size (128) .
42
43
func NewCache [K comparable , V any ](opts ... Option ) * Cache [K , V ] {
43
44
o := newOptions ()
44
45
for _ , optFunc := range opts {
Original file line number Diff line number Diff line change @@ -4,7 +4,12 @@ import (
4
4
"container/heap"
5
5
)
6
6
7
- // Cache is a thread safe LRU cache
7
+ // Cache is used a LFU (Least-frequently used) cache replacement policy.
8
+ //
9
+ // Counts how often an item is needed. Those that are used least often are discarded first.
10
+ // This works very similar to LRU except that instead of storing the value of how recently
11
+ // a block was accessed, we store the value of how many times it was accessed. So of course
12
+ // while running an access sequence we will replace a block which was used fewest times from our cache.
8
13
type Cache [K comparable , V any ] struct {
9
14
cap int
10
15
queue * priorityQueue [K , V ]
Original file line number Diff line number Diff line change @@ -4,7 +4,11 @@ import (
4
4
"container/list"
5
5
)
6
6
7
- // Cache is a thread safe LRU cache
7
+ // Cache is used a LRU (Least recently used) cache replacement policy.
8
+ //
9
+ // Discards the least recently used items first. This algorithm requires
10
+ // keeping track of what was used when, which is expensive if one wants
11
+ // to make sure the algorithm always discards the least recently used item.
8
12
type Cache [K comparable , V any ] struct {
9
13
cap int
10
14
list * list.List
You can’t perform that action at this time.
0 commit comments