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> =
1415
1415
/// How many concurrent index backfill threads to run concurrently.
1416
1416
pub static INDEX_BACKFILL_CONCURRENCY : LazyLock < usize > =
1417
1417
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
12
12
[dependencies ]
13
13
anyhow = { workspace = true }
14
14
bytes = { workspace = true }
15
+ common = { workspace = true }
15
16
futures = { workspace = true }
16
17
http-body-util = { workspace = true }
17
18
http-cache = { workspace = true }
@@ -24,6 +25,7 @@ strum = { workspace = true }
24
25
thiserror = { workspace = true }
25
26
26
27
[dev-dependencies ]
28
+ common = { workspace = true , features = [" testing" ] }
27
29
metrics = { workspace = true , features = [" testing" ] }
28
30
tokio = { workspace = true }
29
31
Original file line number Diff line number Diff line change 1
1
#![ feature( try_blocks) ]
2
2
#![ feature( impl_trait_in_fn_trait_return) ]
3
3
4
- use std:: sync:: LazyLock ;
4
+ use std:: sync:: {
5
+ Arc ,
6
+ LazyLock ,
7
+ } ;
5
8
6
9
use bytes:: BufMut ;
10
+ use common:: knobs:: HTTP_CACHE_SIZE ;
7
11
use futures:: Future ;
8
12
use http_body_util:: BodyExt ;
9
- use http_cache:: XCACHE ;
13
+ use http_cache:: {
14
+ MokaCache ,
15
+ XCACHE ,
16
+ } ;
10
17
use http_cache_reqwest:: {
11
18
Cache ,
12
19
CacheMode ,
@@ -29,7 +36,16 @@ mod metrics;
29
36
#[ error( transparent) ]
30
37
pub struct AsStdError ( #[ from] anyhow:: Error ) ;
31
38
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
+ } ) ;
33
49
static HTTP_CLIENT : LazyLock < reqwest_middleware:: ClientWithMiddleware > = LazyLock :: new ( || {
34
50
ClientBuilder :: new ( Client :: new ( ) )
35
51
. with ( Cache ( HttpCache {
You can’t perform that action at this time.
0 commit comments