File tree Expand file tree Collapse file tree 4 files changed +27
-3
lines changed Expand file tree Collapse file tree 4 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -1415,3 +1415,8 @@ pub static SUBSCRIPTION_ADVANCE_LOG_TRACING_THRESHOLD: LazyLock<u64> =
14151415/// How many concurrent index backfill threads to run concurrently.
14161416pub static INDEX_BACKFILL_CONCURRENCY : LazyLock < usize > =
14171417 LazyLock :: new ( || env_config ( "INDEX_BACKFILL_CONCURRENCY" , 8 ) ) ;
1418+
1419+ /// The max size of the global HTTP cache, in bytes. This is only used for
1420+ /// getting auth metadata right now.
1421+ pub static HTTP_CACHE_SIZE : LazyLock < u64 > =
1422+ LazyLock :: new ( || env_config ( "HTTP_CACHE_SIZE" , 16 * 1024 * 1024 ) ) ;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ doctest = false
1212[dependencies ]
1313anyhow = { workspace = true }
1414bytes = { workspace = true }
15+ common = { workspace = true }
1516futures = { workspace = true }
1617http-body-util = { workspace = true }
1718http-cache = { workspace = true }
@@ -24,6 +25,7 @@ strum = { workspace = true }
2425thiserror = { workspace = true }
2526
2627[dev-dependencies ]
28+ common = { workspace = true , features = [" testing" ] }
2729metrics = { workspace = true , features = [" testing" ] }
2830tokio = { workspace = true }
2931
Original file line number Diff line number Diff line change 11#![ feature( try_blocks) ]
22#![ feature( impl_trait_in_fn_trait_return) ]
33
4- use std:: sync:: LazyLock ;
4+ use std:: sync:: {
5+ Arc ,
6+ LazyLock ,
7+ } ;
58
69use bytes:: BufMut ;
10+ use common:: knobs:: HTTP_CACHE_SIZE ;
711use futures:: Future ;
812use http_body_util:: BodyExt ;
9- use http_cache:: XCACHE ;
13+ use http_cache:: {
14+ MokaCache ,
15+ XCACHE ,
16+ } ;
1017use http_cache_reqwest:: {
1118 Cache ,
1219 CacheMode ,
@@ -29,7 +36,16 @@ mod metrics;
2936#[ error( transparent) ]
3037pub struct AsStdError ( #[ from] anyhow:: Error ) ;
3138
32- static CACHE : LazyLock < MokaManager > = LazyLock :: new ( MokaManager :: default) ;
39+ static CACHE : LazyLock < MokaManager > = LazyLock :: new ( || {
40+ MokaManager :: new (
41+ MokaCache :: builder ( )
42+ . max_capacity ( * HTTP_CACHE_SIZE )
43+ . weigher ( |k : & String , v : & Arc < Vec < u8 > > | {
44+ u32:: try_from ( k. len ( ) + v. len ( ) ) . unwrap_or ( u32:: MAX )
45+ } )
46+ . build ( ) ,
47+ )
48+ } ) ;
3349static HTTP_CLIENT : LazyLock < reqwest_middleware:: ClientWithMiddleware > = LazyLock :: new ( || {
3450 ClientBuilder :: new ( Client :: new ( ) )
3551 . with ( Cache ( HttpCache {
You can’t perform that action at this time.
0 commit comments