1- use std:: collections:: HashSet ;
2-
31use actix_web:: {
42 HttpResponse ,
53 body:: { BoxBody , EitherBody , MessageBody } ,
@@ -22,7 +20,9 @@ pub async fn middleware(
2220 service_request : ServiceRequest ,
2321 next : Next < impl MessageBody >
2422) -> Result < ServiceResponse < EitherBody < impl MessageBody > > , actix_web:: Error > {
25- let match_pattern = service_request. match_pattern ( ) . unwrap_or ( "default" . to_string ( ) ) ;
23+ let match_pattern = service_request
24+ . match_pattern ( )
25+ . unwrap_or ( "default" . to_string ( ) ) ;
2626 let Some ( app_data) = service_request. app_data :: < web:: Data < ApiData > > ( ) else {
2727 // If we don't have ApiData for whatever reason, we can't do much
2828 // cache-related Technically this could probably be an unwrap, but this is
@@ -42,7 +42,9 @@ pub async fn middleware(
4242 }
4343
4444 let cache = app_data. cache . clone ( ) ;
45- let metric_labels = CacheLabels { endpoint : match_pattern } ;
45+ let metric_labels = CacheLabels {
46+ endpoint : match_pattern
47+ } ;
4648 let cache_key = CacheKey {
4749 path : service_request. path ( ) . to_string ( ) ,
4850 query : service_request. query_string ( ) . to_string ( )
@@ -62,7 +64,11 @@ pub async fn middleware(
6264 // Resolve cache entry with path & query
6365 if let Some ( cache_value) = cache. get ( & cache_key) . await {
6466 // Record a cache hit to the metrics
65- app_data. metrics . cache_hits . get_or_create ( & metric_labels) . inc ( ) ;
67+ app_data
68+ . metrics
69+ . cache_hits
70+ . get_or_create ( & metric_labels)
71+ . inc ( ) ;
6672
6773 // Short circuit with HttpResponse::NotModified() if the If-None-Match header
6874 // matches cache
@@ -96,7 +102,11 @@ pub async fn middleware(
96102 return Ok ( service_request. into_response ( res) . map_into_right_body ( ) ) ;
97103 } else {
98104 // Record a cache miss to the metrics
99- app_data. metrics . cache_misses . get_or_create ( & metric_labels) . inc ( ) ;
105+ app_data
106+ . metrics
107+ . cache_misses
108+ . get_or_create ( & metric_labels)
109+ . inc ( ) ;
100110 }
101111
102112 // If none of the caching cases were handled, pass through to other handlers
0 commit comments