Skip to content

Commit 4553f90

Browse files
authored
improve lru clearing for package gcache (#2327)
1 parent ef7fec7 commit 4553f90

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

os/gcache/gcache_adapter_memory.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,17 @@ func (c *AdapterMemory) syncEventAndClearExpired(ctx context.Context) {
427427
}
428428
}
429429
// Processing expired keys from LRU.
430-
if c.cap > 0 && c.lruGetList.Len() > 0 {
431-
for {
432-
if v := c.lruGetList.PopFront(); v != nil {
433-
c.lru.Push(v)
434-
} else {
435-
break
430+
if c.cap > 0 {
431+
if c.lruGetList.Len() > 0 {
432+
for {
433+
if v := c.lruGetList.PopFront(); v != nil {
434+
c.lru.Push(v)
435+
} else {
436+
break
437+
}
436438
}
437439
}
440+
c.lru.SyncAndClear(ctx)
438441
}
439442
// ========================
440443
// Data Cleaning up.

os/gcache/gcache_adapter_memory_lru.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package gcache
88

99
import (
1010
"context"
11-
"time"
1211

1312
"github.com/gogf/gf/v2/container/glist"
1413
"github.com/gogf/gf/v2/container/gmap"
@@ -35,7 +34,6 @@ func newMemCacheLru(cache *AdapterMemory) *adapterMemoryLru {
3534
rawList: glist.New(true),
3635
closed: gtype.NewBool(),
3736
}
38-
gtimer.AddSingleton(context.Background(), time.Second, lru.SyncAndClear)
3937
return lru
4038
}
4139

0 commit comments

Comments
 (0)