Skip to content

Commit

Permalink
feat: new experimental gc friendly flatten cache
Browse files Browse the repository at this point in the history
Signed-off-by: Rueian <[email protected]>
  • Loading branch information
rueian committed Jan 5, 2025
1 parent 76151e2 commit d9d2fb0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,13 @@ func (a *adapterEntry) set(val RedisMessage, err error) {
}

func (a *adapterEntry) Wait(ctx context.Context) (RedisMessage, error) {
ctxCh := ctx.Done()
if ctxCh == nil {
<-a.ch
return a.val, a.err
}
select {
case <-ctx.Done():
case <-ctxCh:
return RedisMessage{}, ctx.Err()
case <-a.ch:
return a.val, a.err
Expand All @@ -191,7 +196,7 @@ type flatentry struct {
ttl int64
size int64
mark int64
mu sync.Mutex
mu sync.RWMutex
}

func (f *flatentry) insert(e *flatentry) {
Expand All @@ -214,9 +219,9 @@ func (f *flatentry) find(cmd string, ts int64) (ret RedisMessage, expired bool)
_ = ret.CacheUnmarshalView(f.val)
return
}
f.mu.Lock()
f.mu.RLock()
ovfl := f.ovfl
f.mu.Unlock()
f.mu.RUnlock()
return ovfl.find(cmd, ts)
}

Expand Down

0 comments on commit d9d2fb0

Please sign in to comment.