Look up a document in the cache. Returns `Some(&[u8])` on hit. Single HashMap lookup on the hot path — counters are bumped via `Cell` so the borrow checker permits `&self` here.
(
&self,
database_id: u64,
tenant_id: u64,
collection: &str,
document_id: &str,
)
| 133 | /// Single HashMap lookup on the hot path — counters are bumped via |
| 134 | /// `Cell` so the borrow checker permits `&self` here. |
| 135 | pub fn get( |
| 136 | &self, |
| 137 | database_id: u64, |
| 138 | tenant_id: u64, |
| 139 | collection: &str, |
| 140 | document_id: &str, |
| 141 | ) -> Option<&[u8]> { |
| 142 | let key = Self::make_key(database_id, tenant_id, collection, document_id); |
| 143 | match self |
| 144 | .shards |
| 145 | .get(&database_id) |
| 146 | .and_then(|shard| shard.entries.get(&key)) |
| 147 | { |
| 148 | Some(v) => { |
| 149 | self.hits.set(self.hits.get() + 1); |
| 150 | Some(v.as_slice()) |
| 151 | } |
| 152 | None => { |
| 153 | self.misses.set(self.misses.get() + 1); |
| 154 | None |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | /// Insert or update a document in the cache (write-through). |
| 160 | pub fn put( |