diff --git a/src/store/reader.rs b/src/store/reader.rs index 388bd6cd03..a6082ac58e 100644 --- a/src/store/reader.rs +++ b/src/store/reader.rs @@ -81,6 +81,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 { @@ -173,6 +177,17 @@ 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. + pub fn cache_key(&self, doc_id: DocId) -> crate::Result { + 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. ///