Skip to content

Commit

Permalink
tweak lock scope
Browse files Browse the repository at this point in the history
  • Loading branch information
dantengsky committed Jan 8, 2025
1 parent b823d10 commit 7580cd9
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/query/storages/common/cache/src/providers/memory_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,18 @@ mod impls {

fn get<Q: AsRef<str>>(&self, k: Q) -> Option<Arc<V>> {
metrics_inc_cache_access_count(1, self.name());
let mut guard = self.inner.write();
match guard.get(k.as_ref()) {
None => {
// TODO move these out lock
metrics_inc_cache_miss_count(1, &self.name);
None
}
Some(cached_value) => {
// TODO move these out of lock
metrics_inc_cache_hit_count(1, &self.name);
Some(cached_value.get_inner())
}
let v = {
let mut guard = self.inner.write();
guard
.get(k.as_ref())
.map(|cache_value: &CacheValue<V>| cache_value.get_inner())
};
if v.is_none() {
metrics_inc_cache_miss_count(1, &self.name);
} else {
metrics_inc_cache_hit_count(1, &self.name);
}
v
}

fn get_sized<Q: AsRef<str>>(&self, k: Q, len: u64) -> Option<Arc<Self::V>> {
Expand Down

0 comments on commit 7580cd9

Please sign in to comment.