Skip to content

Commit 51a6259

Browse files
authored
Merge pull request #12 from Code-Hex/fix/some-comments
fixed some comments
2 parents 7de70b9 + 1d5fe9a commit 51a6259

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

cache.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func newItem[K comparable, V any](key K, val V, opts ...ItemOption) *Item[K, V]
6262
}
6363
}
6464

65-
// Cache is a cache.
65+
// Cache is a thread safe cache.
6666
type Cache[K comparable, V any] struct {
6767
cache Interface[K, *Item[K, V]]
6868
expirations map[K]chan struct{}
@@ -104,7 +104,9 @@ func AsFIFO[K comparable, V any](opts ...fifo.Option) Option[K, V] {
104104
}
105105
}
106106

107-
// New creates a new Cache.
107+
// New creates a new thread safe Cache.
108+
//
109+
// There are several Cache replacement policies available with you specified any options.
108110
func New[K comparable, V any](opts ...Option[K, V]) *Cache[K, V] {
109111
o := newOptions[K, V]()
110112
for _, optFunc := range opts {

fifo/fifo.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
)
66

77
// Cache is used a FIFO (First in first out) cache replacement policy.
8+
//
89
// In FIFO the item that enter the cache first is evicted first
910
// w/o any regard of how often or how many times it was accessed before.
1011
type Cache[K comparable, V any] struct {
@@ -38,7 +39,7 @@ func WithCapacity(cap int) Option {
3839
}
3940
}
4041

41-
// NewCache creates a new cache.
42+
// NewCache creates a new non-thread safe FIFO cache whose capacity is the default size (128).
4243
func NewCache[K comparable, V any](opts ...Option) *Cache[K, V] {
4344
o := newOptions()
4445
for _, optFunc := range opts {

lfu/lfu.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import (
44
"container/heap"
55
)
66

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.
813
type Cache[K comparable, V any] struct {
914
cap int
1015
queue *priorityQueue[K, V]
@@ -31,7 +36,7 @@ func WithCapacity(cap int) Option {
3136
}
3237
}
3338

34-
// NewCache creates a new LFU cache whose capacity is the default size (128).
39+
// NewCache creates a new non-thread safe LFU cache whose capacity is the default size (128).
3540
func NewCache[K comparable, V any](opts ...Option) *Cache[K, V] {
3641
o := newOptions()
3742
for _, optFunc := range opts {

lru/lru.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import (
44
"container/list"
55
)
66

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.
812
type Cache[K comparable, V any] struct {
913
cap int
1014
list *list.List
@@ -36,7 +40,7 @@ func WithCapacity(cap int) Option {
3640
}
3741
}
3842

39-
// NewCache creates a new LRU cache whose capacity is the default size (128).
43+
// NewCache creates a new non-thread safe LRU cache whose capacity is the default size (128).
4044
func NewCache[K comparable, V any](opts ...Option) *Cache[K, V] {
4145
o := newOptions()
4246
for _, optFunc := range opts {

simple/simple.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type entry[V any] struct {
1515
createdAt time.Time
1616
}
1717

18-
// NewCache creates a new cache.
18+
// NewCache creates a new non-thread safe cache.
1919
func NewCache[K comparable, V any]() *Cache[K, V] {
2020
return &Cache[K, V]{
2121
items: make(map[K]*entry[V], 0),

0 commit comments

Comments
 (0)