Inserts the given value at the given key. If the record already exists, the previous value is replaced.
(&self, key: Self::Key, value: Self::Value)
| 134 | /// |
| 135 | /// If the record already exists, the previous value is replaced. |
| 136 | fn insert(&self, key: Self::Key, value: Self::Value) { |
| 137 | let key_raw = key.into_raw(); |
| 138 | let value_bytes = rkyv::to_bytes(&value).unwrap(); |
| 139 | |
| 140 | // Update cache |
| 141 | if Self::CACHE_SIZE > 0 { |
| 142 | let mut cache = self.cache().lock().unwrap(); |
| 143 | cache.put(key_raw.as_ref().to_vec(), value_bytes.to_vec()); |
| 144 | } |
| 145 | |
| 146 | match Self::MERGE_OP { |
| 147 | MergeOperator::Default => self.raw().put(key_raw, value_bytes).unwrap(), |
| 148 | MergeOperator::Associative(_) => self.raw().merge(key_raw, value_bytes).unwrap(), |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | /// Create a new insertion batch. |
| 153 | fn batched_insert(&self) -> InsertionBatch<'_, Self> { |