fn drop(&mut self) {
        // take the bytes from the aggreator. if the bytes have already been taken
        // or the bytes have been poisoned (because of an error), this will ret None
        let bytes = match self.agg.take() {
            Some(b) => b,
            None => {
                log::warn!("no byte aggregator found, skipping cache save");
                // if poisoned, then mark as a failed request
                if self.agg.is_poisoned() {
                    self.gs.metrics.failed_requests_total.inc();
                }
                return;
            }
        };

        // spawn a cache save task with tokio
        let bytes_len = bytes.len() as u64;
        let gs = Arc::clone(&self.gs);
        let cache_info = Arc::clone(&self.cache_info);
        tokio::spawn(async move {
            let (key, mime) = cache_info.as_ref();

            let timer = crate::utils::Timer::start();
            gs.cache.save(key, mime.to_string(), bytes).await;
            log::debug!("cache save in {}", timer);
            gs.metrics
                .cache_save_histo
                .observe(timer.elapsed_secs() as f64);
        });

        // update all metrics
        self.gs
            .metrics
            .miss_request_process_seconds
            .observe(self.req_start.elapsed_secs() as f64);
        self.gs.metrics.miss_requests_total.inc();
        self.gs.metrics.bytes_up.inc_by(bytes_len);
        self.gs.metrics.bytes_down.inc_by(bytes_len);
    }
/// Schedules a tokio task to save the cache aggregator when this value is dropped
Schedules a tokio task to save the cache aggregator when this value is dropped
Schedules a tokio task to save the cache aggregator when this value is dropped
fn drop(&mut self) {
        // take the bytes from the aggreator. if the bytes have already been taken
        // or the bytes have been poisoned (because of an error), this will ret None
        let bytes = match self.agg.take() {
            Some(b) => b,
            None => {
                log::warn!("no byte aggregator found, skipping cache save");
                // if poisoned, then mark as a failed request
                if self.agg.is_poisoned() {
                    self.gs.metrics.failed_requests_total.inc();
                }
                return;
            }
        };
        // spawn a cache save task with tokio
        let bytes_len = bytes.len() as u64;
        let gs = Arc::clone(&self.gs);
        let cache_info = Arc::clone(&self.cache_info);
        tokio::spawn(async move {
            let (key, mime) = cache_info.as_ref();
            let timer = crate::utils::Timer::start();
            gs.cache.save(key, mime.to_string(), bytes).await;
            log::debug!("cache save in {}", timer);
            gs.metrics
                .cache_save_histo
                .observe(timer.elapsed_secs() as f64);
        });
        // update all metrics
        self.gs
            .metrics
            .miss_request_process_seconds
            .observe(self.req_start.elapsed_secs() as f64);
        self.gs.metrics.miss_requests_total.inc();
        self.gs.metrics.bytes_up.inc_by(bytes_len);
        self.gs.metrics.bytes_down.inc_by(bytes_len);
    }
fn drop ( & mut self ) { // take the bytes from the aggreator. if the bytes have already been taken // or the bytes have been poisoned (because of an error), this will ret None let bytes = match self . agg . take ( ) { Some ( b ) => b , None => { log :: warn ! ( " " ) ; // if poisoned, then mark as a failed request if self . agg . is_poisoned ( ) { self . gs . metrics . failed_requests_total . inc ( ) ; } return ; } } ; // spawn a cache save task with tokio let bytes_len = bytes . len ( ) as u64 ; let gs = Arc :: clone ( & self . gs ) ; let cache_info = Arc :: clone ( & self . cache_info ) ; tokio :: spawn ( async move { let ( key , mime ) = cache_info . as_ref ( ) ; let timer = crate :: utils :: Timer :: start ( ) ; gs . cache . save ( key , mime . to_string ( ) , bytes ) . await ; log :: debug ! ( " " timer ) ; gs . metrics . cache_save_histo . observe ( timer . elapsed_secs ( ) as f64 ) ; } ) ; // update all metrics self . gs . metrics . miss_request_process_seconds . observe ( self . req_start . elapsed_secs ( ) as f64 ) ; self . gs . metrics . miss_requests_total . inc ( ) ; self . gs . metrics . bytes_up . inc_by ( bytes_len ) ; self . gs . metrics . bytes_down . inc_by ( bytes_len ) ; }
Schedules a tokio task to save the cache aggregator when this value is dropped
Schedules a tokio task to save the cache aggregator when this value is dropped
&mut self