Skip to content

Commit

Permalink
Allow cheaply cloning a StoreReader to enable user control over block…
Browse files Browse the repository at this point in the history
… cache usage.
  • Loading branch information
adamreichold committed Dec 11, 2023
1 parent bff7c58 commit f4d8c44
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/store/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@ impl Sum for CacheStats {
}
}

impl Clone for StoreReader {
/// Creates a clone of the given store reader but using an independent block cache.
fn clone(&self) -> Self {
Self {
decompressor: self.decompressor,
data: self.data.clone(),
cache: BlockCache {
cache: self
.cache
.cache
.as_ref()
.map(|cache| Mutex::new(LruCache::new(cache.lock().unwrap().cap()))),
cache_hits: Default::default(),
cache_misses: Default::default(),
},
skip_index: Arc::clone(&self.skip_index),
space_usage: self.space_usage.clone(),
}
}
}

impl StoreReader {
/// Opens a store reader
///
Expand Down

0 comments on commit f4d8c44

Please sign in to comment.