Skip to content

Commit 504c6b4

Browse files
committed
Drop mandatory capacity when LFU is used
1 parent 8efabe9 commit 504c6b4

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

cache.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,19 @@ func (build Builder) WithEvictionCallback(cb EvictionCallback) Builder {
6868

6969
// WithCapacity configures the cache with specified capacity.
7070
//
71-
// If cache exceeds the limit, the eldest record is evicted.
71+
// If cache exceeds the limit, the eldest record is evicted or
72+
// if LFU is enabled, the least frequently used record is evicted.
7273
func (build Builder) WithCapacity(capacity uint32) Builder {
7374
return func(c *Cache) {
7475
build(c)
7576
c.list = newRingList(capacity)
7677
}
7778
}
7879

79-
// WithLFU enables the eventual LFU ordering of records.
80-
//
81-
// New records are inserted as the most frequently used to
82-
// reduce premature eviction of new but unused records.
80+
// WithLFU enables eventual LFU ordering of records.
8381
func (build Builder) WithLFU() Builder {
8482
return func(c *Cache) {
8583
build(c)
86-
if c.list == nil {
87-
panic("evcache: WithLFU requires WithCapacity")
88-
}
8984
c.lfuEnabled = true
9085
}
9186
}

0 commit comments

Comments
 (0)