impr(cachekv): Move check outside lock. (#14831)

This commit is contained in:
Devon Bear 2023-01-30 05:48:57 -05:00 committed by GitHub
parent 5f08a5c9b0
commit 1b6e683180
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -69,12 +69,11 @@ func (store *Store) Get(key []byte) (value []byte) {
// Set implements types.KVStore.
func (store *Store) Set(key []byte, value []byte) {
store.mtx.Lock()
defer store.mtx.Unlock()
types.AssertValidKey(key)
types.AssertValidValue(value)
store.mtx.Lock()
defer store.mtx.Unlock()
store.setCacheValue(key, value, true)
}
@ -86,10 +85,11 @@ func (store *Store) Has(key []byte) bool {
// Delete implements types.KVStore.
func (store *Store) Delete(key []byte) {
types.AssertValidKey(key)
store.mtx.Lock()
defer store.mtx.Unlock()
types.AssertValidKey(key)
store.setCacheValue(key, nil, true)
}