Skip to content

Commit 163e16b

Browse files
author
coder2z
committed
cache
1 parent 82bbe2e commit 163e16b

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

xcache/lru/lru.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,23 @@ type Cache struct {
88
nbytes int64
99
ll *list.List
1010
cache map[string]*list.Element
11-
// optional and executed when an entry is purged.
12-
OnEvicted func(key string, value Value)
1311
}
1412

1513
type entry struct {
1614
key string
1715
value Value
1816
}
1917

20-
// Value use Len to count how many bytes it takes
2118
type Value interface {
2219
Len() int
2320
}
2421

2522
// New is the Constructor of Cache
26-
func New(maxBytes int64, onEvicted func(string, Value)) *Cache {
23+
func New(maxBytes int64) *Cache {
2724
return &Cache{
28-
maxBytes: maxBytes,
29-
ll: list.New(),
30-
cache: make(map[string]*list.Element),
31-
OnEvicted: onEvicted,
25+
maxBytes: maxBytes,
26+
ll: list.New(),
27+
cache: make(map[string]*list.Element),
3228
}
3329
}
3430

@@ -67,9 +63,6 @@ func (c *Cache) RemoveOldest() {
6763
kv := ele.Value.(*entry)
6864
delete(c.cache, kv.key)
6965
c.nbytes -= int64(len(kv.key)) + int64(kv.value.Len())
70-
if c.OnEvicted != nil {
71-
c.OnEvicted(kv.key, kv.value)
72-
}
7366
}
7467
}
7568

0 commit comments

Comments
 (0)