dgraph-io / ristretto

A high performance memory-bound Go cache

Home Page:https://dgraph.io/blog/post/introducing-ristretto-high-perf-go-cache/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Delete operation performs the store.delete twice

jarifibrahim opened this issue · comments

When an item is deleted by cache.Del(key), we delete it from the store on the following line

ristretto/cache.go

Lines 248 to 259 in a093fe6

// Delete immediately.
c.store.Del(keyHash, conflictHash)
// If we've set an item, it would be applied slightly later.
// So we must push the same item to `setBuf` with the deletion flag.
// This ensures that if a set is followed by a delete, it will be
// applied in the correct order.
c.setBuf <- &item{
flag: itemDelete,
key: keyHash,
conflict: conflictHash,
}
}

the same item is deleted again in the process() goroutine

ristretto/cache.go

Lines 331 to 334 in a093fe6

case itemDelete:
c.policy.Del(i.key) // Deals with metrics updates.
c.store.Del(i.key, i.conflict)
}

I don't think there's a major side-effect of doing this but we're doing unnecessary work by deleting an already deleted key.

Github issues have been deprecated.
This issue has been moved to discuss. You can follow the conversation there and also subscribe to updates by changing your notification preferences.

drawing