mirror of
https://gitee.com/johng/gf
synced 2026-07-07 06:15:15 +08:00
improve lru clearing for package gcache (#2327)
This commit is contained in:
@ -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.
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user