@@ -19,6 +19,7 @@ pub struct CachedFetchResult {
1919 pub headers : HeaderMap ,
2020 pub cached_at : Instant ,
2121 pub was_cached : bool ,
22+ pub tags : Vec < String > ,
2223}
2324type InFlightFetches =
2425 Arc < DashMap < String , Arc < TokioMutex < Option < Result < CachedFetchResult , RariError > > > > > > ;
@@ -77,7 +78,7 @@ impl RequestContext {
7778 fn generate_cache_key ( url : & str , options : & FxHashMap < String , String > ) -> String {
7879 let cache_relevant_options: FxHashMap < _ , _ > = options
7980 . iter ( )
80- . filter ( |( k, _) | !matches ! ( k. as_str( ) , "cacheTTLMs" | "timeout" ) )
81+ . filter ( |( k, _) | !matches ! ( k. as_str( ) , "cacheTTLMs" | "timeout" | "tags" ) )
8182 . collect ( ) ;
8283
8384 if cache_relevant_options. is_empty ( ) {
@@ -113,6 +114,9 @@ impl RequestContext {
113114 ) -> Result < CachedFetchResult , RariError > {
114115 let cache_key = Self :: generate_cache_key ( url, & options) ;
115116
117+ let tags: Vec < String > =
118+ options. get ( "tags" ) . and_then ( |t| serde_json:: from_str ( t) . ok ( ) ) . unwrap_or_default ( ) ;
119+
116120 {
117121 let mut cache = self . fetch_cache . lock ( ) ;
118122 if let Some ( cached) = cache. get ( & cache_key) {
@@ -157,7 +161,11 @@ impl RequestContext {
157161 cache_key : cache_key. clone ( ) ,
158162 } ;
159163
160- let fetch_result = self . perform_fetch ( url, & options) . await ;
164+ let mut fetch_result = self . perform_fetch ( url, & options) . await ;
165+
166+ if let Ok ( ref mut result) = fetch_result {
167+ result. tags = tags;
168+ }
161169
162170 * guard = Some ( fetch_result. clone ( ) ) ;
163171
@@ -210,6 +218,7 @@ impl RequestContext {
210218 headers,
211219 cached_at : Instant :: now ( ) ,
212220 was_cached : false ,
221+ tags : Vec :: new ( ) ,
213222 } )
214223 }
215224}
@@ -240,6 +249,7 @@ mod tests {
240249 headers : HeaderMap :: new ( ) ,
241250 cached_at : Instant :: now ( ) ,
242251 was_cached : false ,
252+ tags : Vec :: new ( ) ,
243253 } ;
244254
245255 let test_key = format ! ( "https://test-{}.example.com" , uuid:: Uuid :: new_v4( ) ) ;
0 commit comments