Skip to content

Commit

Permalink
improve lru clearing for package gcache (#2327)
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn authored Nov 25, 2022
1 parent ef7fec7 commit 4553f90
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 9 additions & 6 deletions os/gcache/gcache_adapter_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions os/gcache/gcache_adapter_memory_lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package gcache

import (
"context"
"time"

"github.com/gogf/gf/v2/container/glist"
"github.com/gogf/gf/v2/container/gmap"
Expand All @@ -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
}

Expand Down

0 comments on commit 4553f90

Please sign in to comment.