pub(super) async fn response_from_cache(
    uid: &str, // unique-id that represents the request (used for logging)
    req: &HttpRequest,
    gs: &Arc<GlobalState>,
    key: ImageKey,
    req_start: Timer,
) -> HttpResponse {
    // attempt to load image from cache (timing response times)
    let cache_hit = {
        let timer = Timer::start();
        let cache_hit = gs.cache.load(&key).await;
        log::debug!("({}) cache lookup in {}", uid, timer);
        gs.metrics
            .cache_load_seconds
            .observe(timer.elapsed_secs() as f64);
        cache_hit
    };

    if let Some(cache_hit) = cache_hit {
        // found in cache, aka HIT
        let res = handle_cache_hit(uid, gs, req, cache_hit);
        // NOTE: recording metrics here because handle_cache_hit doesn't
        // contain logic for failure
        gs.metrics
            .hit_request_process_seconds
            .observe(req_start.elapsed_secs() as f64);
        gs.metrics.hit_requests_total.inc();
        res
    } else {
        // the result was not found in cache, aka MISS
        // NOTE: metrics are handled in chunked.rs
        handle_cache_miss(uid, gs, key, req_start).await
    }
}
/// Generates an [`HttpResponse`] by querying the cache and either returning HIT data or polling
/// upstream, proxying, and saving the result on MISS.
Generates an [`HttpResponse`] by querying the cache and either returning HIT data or polling
upstream, proxying, and saving the result on MISS.
Generates an [ ` HttpResponse ` ] by querying the cache and either returning HIT data or polling upstream proxying and saving the result on MISS .
pub(super) async fn response_from_cache(
    uid: &str, // unique-id that represents the request (used for logging)
    req: &HttpRequest,
    gs: &Arc<GlobalState>,
    key: ImageKey,
    req_start: Timer,
) -> HttpResponse {
    // attempt to load image from cache (timing response times)
    let cache_hit = {
        let timer = Timer::start();
        let cache_hit = gs.cache.load(&key).await;
        log::debug!("({}) cache lookup in {}", uid, timer);
        gs.metrics
            .cache_load_seconds
            .observe(timer.elapsed_secs() as f64);
        cache_hit
    };
    if let Some(cache_hit) = cache_hit {
        // found in cache, aka HIT
        let res = handle_cache_hit(uid, gs, req, cache_hit);
        // NOTE: recording metrics here because handle_cache_hit doesn't
        // contain logic for failure
        gs.metrics
            .hit_request_process_seconds
            .observe(req_start.elapsed_secs() as f64);
        gs.metrics.hit_requests_total.inc();
        res
    } else {
        // the result was not found in cache, aka MISS
        // NOTE: metrics are handled in chunked.rs
        handle_cache_miss(uid, gs, key, req_start).await
    }
}
pub ( super ) async fn response_from_cache ( uid : & str , // unique-id that represents the request (used for logging) req : & HttpRequest , gs : & Arc < GlobalState > , key : ImageKey , req_start : Timer , ) -> HttpResponse { // attempt to load image from cache (timing response times) let cache_hit = { let timer = Timer :: start ( ) ; let cache_hit = gs . cache . load ( & key ) . await ; log :: debug ! ( " " uid timer ) ; gs . metrics . cache_load_seconds . observe ( timer . elapsed_secs ( ) as f64 ) ; cache_hit } ; if let Some ( cache_hit ) = cache_hit { // found in cache, aka HIT let res = handle_cache_hit ( uid , gs , req , cache_hit ) ; // NOTE: recording metrics here because handle_cache_hit doesn't // contain logic for failure gs . metrics . hit_request_process_seconds . observe ( req_start . elapsed_secs ( ) as f64 ) ; gs . metrics . hit_requests_total . inc ( ) ; res } else { // the result was not found in cache, aka MISS // NOTE: metrics are handled in chunked.rs handle_cache_miss ( uid , gs , key , req_start ) . await } }
Generates an [`HttpResponse`] by querying the cache and either returning HIT data or polling
upstream, proxying, and saving the result on MISS.
Generates an [ ` HttpResponse ` ] by querying the cache and either returning HIT data or polling upstream proxying and saving the result on MISS .
uid
&str
req
&HttpRequest
gs
&Arc<GlobalState>
key
ImageKey
req_start
Timer