Skip to content

Commit

Permalink
fix: use usize as bytes capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
dantengsky committed Jan 8, 2025
1 parent ec22ba3 commit 7e4c12e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/common/cache/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ pub trait Cache<K: Eq + Hash + MemSized, V: MemSized> {

fn items_capacity(&self) -> u64;

fn set_bytes_capacity(&mut self, capacity: u64);
fn set_bytes_capacity(&mut self, capacity: usize);

fn set_items_capacity(&mut self, capacity: u64);
fn set_items_capacity(&mut self, capacity: usize);

/// Returns the bytes size of all the key-value pairs in the cache.
fn bytes_size(&self) -> u64;
Expand Down
13 changes: 6 additions & 7 deletions src/common/cache/src/cache/lru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,19 +301,18 @@ impl<K: Eq + Hash + MemSized, V: MemSized> Cache<K, V> for LruCache<K, V> {
self.max_items as u64
}

fn set_bytes_capacity(&mut self, capacity: u64) {
// TODO refine this
while self.bytes > self.max_bytes || self.map.len() > self.max_items {
fn set_bytes_capacity(&mut self, max_bytes: usize) {
while self.bytes > max_bytes || self.map.len() > self.max_items {
self.pop_by_policy();
}
self.max_bytes = capacity as usize;
self.max_bytes = max_bytes;
}

fn set_items_capacity(&mut self, capacity: u64) {
while self.bytes > self.max_bytes || self.map.len() > self.max_items {
fn set_items_capacity(&mut self, max_items: usize) {
while self.bytes > self.max_bytes || self.map.len() > max_items {
self.pop_by_policy();
}
self.max_items = capacity as usize;
self.max_items = max_items;
}

/// Returns the bytes size of all the key-value pairs in the cache.
Expand Down
6 changes: 2 additions & 4 deletions src/query/storages/common/cache/src/providers/memory_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ pub struct InMemoryLruCache<V: Into<CacheValue<V>>> {
impl<V: Into<CacheValue<V>>> InMemoryLruCache<V> {
pub fn set_bytes_capacity(&self, capacity: usize) {
let mut cache = self.inner.write();
// TODO no as please
cache.set_bytes_capacity(capacity as u64);
cache.set_bytes_capacity(capacity);
}

pub fn set_items_capacity(&self, capacity: usize) {
let mut cache = self.inner.write();
// TODO no as please
cache.set_items_capacity(capacity as u64);
cache.set_items_capacity(capacity);
}
}

Expand Down

0 comments on commit 7e4c12e

Please sign in to comment.