improve lru clearing for package gcache (#2327)

This commit is contained in:
John Guo
2022-11-25 10:45:56 +08:00
committed by GitHub
parent ef7fec7e24
commit 4553f90a83
2 changed files with 9 additions and 8 deletions

View File

@ -427,14 +427,17 @@ func (c *AdapterMemory) syncEventAndClearExpired(ctx context.Context) {
}
}
// Processing expired keys from LRU.
if c.cap > 0 && c.lruGetList.Len() > 0 {
for {
if v := c.lruGetList.PopFront(); v != nil {
c.lru.Push(v)
} else {
break
if c.cap > 0 {
if c.lruGetList.Len() > 0 {
for {
if v := c.lruGetList.PopFront(); v != nil {
c.lru.Push(v)
} else {
break
}
}
}
c.lru.SyncAndClear(ctx)
}
// ========================
// Data Cleaning up.

View File

@ -8,7 +8,6 @@ package gcache
import (
"context"
"time"
"github.com/gogf/gf/v2/container/glist"
"github.com/gogf/gf/v2/container/gmap"
@ -35,7 +34,6 @@ func newMemCacheLru(cache *AdapterMemory) *adapterMemoryLru {
rawList: glist.New(true),
closed: gtype.NewBool(),
}
gtimer.AddSingleton(context.Background(), time.Second, lru.SyncAndClear)
return lru
}