mirror of
https://gitee.com/johng/gf.git
synced 2024-11-29 18:57:44 +08:00
fix(os/gcache): a little memory leak for removed timestamp key (#3779)
This commit is contained in:
parent
e186eab1a5
commit
d8b06d056e
@ -46,7 +46,7 @@ var (
|
||||
CodeNotFound = localCode{65, "Not Found", nil} // Resource does not exist.
|
||||
CodeInvalidRequest = localCode{66, "Invalid Request", nil} // Invalid request.
|
||||
CodeNecessaryPackageNotImport = localCode{67, "Necessary Package Not Import", nil} // It needs necessary package import.
|
||||
CodeInternalPanic = localCode{68, "Internal Panic", nil} // An panic occurred internally.
|
||||
CodeInternalPanic = localCode{68, "Internal Panic", nil} // A panic occurred internally.
|
||||
CodeBusinessValidationFailed = localCode{300, "Business Validation Failed", nil} // Business validation failed.
|
||||
)
|
||||
|
||||
|
@ -290,7 +290,7 @@ func (c *AdapterMemory) Remove(ctx context.Context, keys ...interface{}) (*gvar.
|
||||
for _, key := range removedKeys {
|
||||
c.eventList.PushBack(&adapterMemoryEvent{
|
||||
k: key,
|
||||
e: gtime.TimestampMilli() - 1000000,
|
||||
e: gtime.TimestampMilli() - 1000,
|
||||
})
|
||||
}
|
||||
return gvar.New(value), nil
|
||||
@ -416,12 +416,13 @@ func (c *AdapterMemory) syncEventAndClearExpired(ctx context.Context) {
|
||||
oldExpireTime = c.expireTimes.Get(event.k)
|
||||
// Calculating the new expiration time set.
|
||||
newExpireTime = c.makeExpireKey(event.e)
|
||||
// Expiration changed for this key.
|
||||
if newExpireTime != oldExpireTime {
|
||||
c.expireSets.GetOrNew(newExpireTime).Add(event.k)
|
||||
if oldExpireTime != 0 {
|
||||
c.expireSets.GetOrNew(oldExpireTime).Remove(event.k)
|
||||
}
|
||||
// Updating the expired time for <event.k>.
|
||||
// Updating the expired time for `event.k`.
|
||||
c.expireTimes.Set(event.k, newExpireTime)
|
||||
}
|
||||
// Adding the key the LRU history by writing operations.
|
||||
|
@ -13,8 +13,10 @@ import (
|
||||
)
|
||||
|
||||
type adapterMemoryExpireSets struct {
|
||||
mu sync.RWMutex // expireSetMu ensures the concurrent safety of expireSets map.
|
||||
expireSets map[int64]*gset.Set // expireSets is the expiring timestamp to its key set mapping, which is used for quick indexing and deleting.
|
||||
// expireSetMu ensures the concurrent safety of expireSets map.
|
||||
mu sync.RWMutex
|
||||
// expireSets is the expiring timestamp in seconds to its key set mapping, which is used for quick indexing and deleting.
|
||||
expireSets map[int64]*gset.Set
|
||||
}
|
||||
|
||||
func newAdapterMemoryExpireSets() *adapterMemoryExpireSets {
|
||||
|
Loading…
Reference in New Issue
Block a user