pub fn insert(&mut self, run_id: &str) -> Option<String> {
        let res = if self.cache.len() < self.cache.cap() {
            // Blindly add a record into the cache, since it still has capacity.
            self.cache.put(run_id.to_owned(), ());
            None
        } else if self.cache.cap() == 0 {
            // Run id should be evicted right away as cache size is 0.
            Some(run_id.to_owned())
        } else {
            let maybe_got_evicted = self.cache.peek_lru().map(|r| r.0.clone());
            let not_cached = self.cache.put(run_id.to_owned(), ()).is_none();
            not_cached.then(|| maybe_got_evicted).flatten()
        };

        self.metrics.cache_size(self.cache.len() as u64);

        res
    }
/// Inserts a record associated with the run id into the lru cache.
/// Once cache reaches capacity, overflow records will be returned back to the caller.
Inserts a record associated with the run id into the lru cache.
Once cache reaches capacity, overflow records will be returned back to the caller.
Inserts a record associated with the run id into the lru cache . Once cache reaches capacity overflow records will be returned back to the caller .
pub fn insert(&mut self, run_id: &str) -> Option<String> {
        let res = if self.cache.len() < self.cache.cap() {
            // Blindly add a record into the cache, since it still has capacity.
            self.cache.put(run_id.to_owned(), ());
            None
        } else if self.cache.cap() == 0 {
            // Run id should be evicted right away as cache size is 0.
            Some(run_id.to_owned())
        } else {
            let maybe_got_evicted = self.cache.peek_lru().map(|r| r.0.clone());
            let not_cached = self.cache.put(run_id.to_owned(), ()).is_none();
            not_cached.then(|| maybe_got_evicted).flatten()
        };
        self.metrics.cache_size(self.cache.len() as u64);
        res
    }
pub fn insert ( & mut self , run_id : & str ) -> Option < String > { let res = if self . cache . len ( ) < self . cache . cap ( ) { // Blindly add a record into the cache, since it still has capacity. self . cache . put ( run_id . to_owned ( ) , ( ) ) ; None } else if self . cache . cap ( ) == 0 { // Run id should be evicted right away as cache size is 0. Some ( run_id . to_owned ( ) ) } else { let maybe_got_evicted = self . cache . peek_lru ( ) . map ( | r | r . 0 . clone ( ) ) ; let not_cached = self . cache . put ( run_id . to_owned ( ) , ( ) ) . is_none ( ) ; not_cached . then ( | | maybe_got_evicted ) . flatten ( ) } ; self . metrics . cache_size ( self . cache . len ( ) as u64 ) ; res }
Inserts a record associated with the run id into the lru cache.
Inserts a record associated with the run id into the lru cache .
&mut self
run_id
&str
&mut self
run_id
&str