MCPcopy Create free account
hub / github.com/dfinity/orbit / insert

Method insert

core/station/impl/src/core/cache.rs:37–50  ·  view source on GitHub ↗

Inserts a key-value pair into the cache.

(&mut self, key: Key, value: Value)

Source from the content-addressed store, hash-verified

35
36 /// Inserts a key-value pair into the cache.
37 pub fn insert(&mut self, key: Key, value: Value) {
38 // Remove an element if the cache is full.
39 let key_to_remove = if self.map.len() >= self.max_size {
40 self.map.keys().next().cloned()
41 } else {
42 None
43 };
44
45 if let Some(key) = key_to_remove {
46 self.map.remove(&key);
47 }
48
49 self.map.insert(key, value);
50 }
51
52 /// Returns a reference to the value at the key if it exists.
53 pub fn get(&self, key: &Key) -> Option<&Value> {

Calls 3

keysMethod · 0.80
lenMethod · 0.45
removeMethod · 0.45