Skip to content

Commit

Permalink
Expose which documents cache together to user code.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreichold committed Dec 11, 2023
1 parent 19a773d commit 6fe01c4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/store/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ impl BlockCache {
}
}

/// Opaque cache key which indicates which documents are cached together.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct CacheKey(usize);

#[derive(Debug, Default)]
/// CacheStats for the `StoreReader`.
pub struct CacheStats {
Expand Down Expand Up @@ -167,6 +171,20 @@ impl StoreReader {
self.cache.stats()
}

/// Returns the cache key for a given document
///
/// These keys are opaque and are not used with the public API,
/// but having the same cache key means that the documents
/// will only require one I/O and decompression operation
/// when retrieve from the same store reader consecutively.
///
/// Note that looking up the cache key of a document
/// will not yet pull anything into the block cache.
pub fn cache_key(&self, doc_id: DocId) -> crate::Result<CacheKey> {
let checkpoint = self.block_checkpoint(doc_id)?;
Ok(CacheKey(checkpoint.byte_range.start))
}

/// Get checkpoint for `DocId`. The checkpoint can be used to load a block containing the
/// document.
///
Expand Down

0 comments on commit 6fe01c4

Please sign in to comment.