Skip to content

Commit 18ad84c

Browse files
committed
fixed some points to use Reference method
1 parent 8ff7701 commit 18ad84c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lru/lru.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func (c *Cache[K, V]) Get(key K) (zero V, _ bool) {
4343
if item.HasExpired() {
4444
return
4545
}
46+
item.Referenced()
4647
// updates cache order
4748
c.list.MoveToFront(e)
4849
return item.Value, true
@@ -56,7 +57,9 @@ func (c *Cache[K, V]) Set(key K, val V, opts ...cache.ItemOption) {
5657
if e, ok := c.items[key]; ok {
5758
// updates cache order
5859
c.list.MoveToFront(e)
59-
e.Value.(*cache.Item[K, V]).Value = val
60+
item := e.Value.(*cache.Item[K, V])
61+
item.Value = val
62+
item.Referenced()
6063
return
6164
}
6265

simple/simple.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func (c *Cache[K, V]) Get(k K) (val V, ok bool) {
4343
if got.HasExpired() {
4444
return
4545
}
46+
got.Referenced()
4647
return got.Value, true
4748
}
4849

0 commit comments

Comments
 (0)