fix: memory leak when gcache.NewAdapterMemory with lru (#3241)

This commit is contained in:
Gin 2024-01-03 20:03:19 +08:00 committed by GitHub
parent 8af1eb693e
commit 5a01798481
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 5 deletions

View File

@ -67,6 +67,9 @@ func NewAdapterMemory(lruCap ...int) Adapter {
c.cap = lruCap[0]
c.lru = newMemCacheLru(c)
}
// Here may be a "timer leak" if adapter is manually changed from memory adapter.
// Do not worry about this, as adapter is less changed, and it does nothing if it's not used.
gtimer.AddSingleton(context.Background(), time.Second, c.syncEventAndClearExpired)
return c
}

View File

@ -8,9 +8,7 @@ package gcache
import (
"context"
"time"
"github.com/gogf/gf/v2/os/gtimer"
"github.com/gogf/gf/v2/util/gconv"
)
@ -29,9 +27,6 @@ func New(lruCap ...int) *Cache {
c := &Cache{
localAdapter: memAdapter,
}
// Here may be a "timer leak" if adapter is manually changed from memory adapter.
// Do not worry about this, as adapter is less changed, and it does nothing if it's not used.
gtimer.AddSingleton(context.Background(), time.Second, memAdapter.(*AdapterMemory).syncEventAndClearExpired)
return c
}