hyperlane_plugin_cache/const.rs
1/// Diagnostic header indicating cache lookup outcome (`HIT`, `MISS`, or `BYPASS`).
2pub const HEADER_X_CACHE: &str = "x-cache";
3
4/// `X-Cache` value emitted when served directly from cache.
5pub const X_CACHE_HIT: &str = "HIT";
6
7/// `X-Cache` value emitted when computed by the origin handler.
8pub const X_CACHE_MISS: &str = "MISS";
9
10/// `X-Cache` value emitted when caching is bypassed by policy or headers.
11pub const X_CACHE_BYPASS: &str = "BYPASS";
12
13/// Default response cache TTL in milliseconds (60 seconds).
14pub const DEFAULT_CACHE_TTL_MS: u64 = 60_000;
15
16/// Default maximum cached response count across all shards.
17pub const DEFAULT_CACHE_MAX_ENTRIES: usize = 16_384;
18
19/// Default maximum total cached byte budget (64 MiB).
20pub const DEFAULT_CACHE_MAX_BYTES: usize = 64 * 1024 * 1024;
21
22/// Default maximum single response body eligible for HTTP response caching (1 MiB).
23pub const DEFAULT_CACHE_MAX_ENTRY_BYTES: usize = 1024 * 1024;
24
25/// Number of independent cache shards (`64`, power of two).
26pub(crate) const CACHE_SHARD_COUNT: usize = 64;
27
28/// Maximum decimal digit buffer capacity for stack formatting a `u64` `Age` header value.
29pub(crate) const AGE_STACK_BUF_LEN: usize = 20;
30
31/// Fast-path stack wire assembly capacity for small HTTP/1.1 cache hit responses.
32pub(crate) const CACHE_WIRE_FAST_STACK_CAP: usize = 512;
33
34/// Maximum prebuilt HTTP/1.1 cache hit response length assembled on the stack without heap allocation.
35pub(crate) const CACHE_WIRE_STACK_CAP: usize = 4096;
36
37/// FNV-1a 64-bit offset basis used for fast cache shard selection.
38pub(crate) const CACHE_FNV1A_OFFSET_BASIS: u64 = 0xcbf2_9ce4_8422_2325;
39
40/// First SplitMix64 multiplier used for fast 8-byte word cache shard selection.
41pub(crate) const CACHE_SHARD_MUL1: u64 = 0xBF58_476D_1CE4_E5B9;
42
43/// Second SplitMix64 multiplier used for tail word cache shard selection.
44pub(crate) const CACHE_SHARD_MUL2: u64 = 0x94D0_49BB_1331_11EB;
45
46/// Prebuilt HTTP/1.1 diagnostic header block inserted before the decimal `Age` value.
47pub(crate) const CACHE_WIRE_DIAG_PREFIX: &[u8] = b"x-cache: HIT\r\nage: ";
48
49/// CRLF separator terminating HTTP/1.1 headers.
50pub(crate) const CACHE_WIRE_CRLF: &[u8] = b"\r\n";
51
52/// Double-CRLF sequence separating HTTP/1.1 headers from the response body.
53pub(crate) const CACHE_WIRE_HEADER_END: &[u8] = b"\r\n\r\n";
54
55/// Context attribute key passing the computed HTTP cache key from request hook to response hook.
56pub(crate) const ATTR_HTTP_CACHE_KEY: &str = "hyperlane_plugin_cache_key";
57
58/// `Cache-Control` directive prohibiting storing a response.
59pub(crate) const CC_NO_STORE: &str = "no-store";
60
61/// `Cache-Control` directive prohibiting unvalidated reuse.
62pub(crate) const CC_NO_CACHE: &str = "no-cache";
63
64/// `Cache-Control` directive marking a response private to a single user.
65pub(crate) const CC_PRIVATE: &str = "private";
66
67/// `Cache-Control` `max-age=` prefix.
68pub(crate) const CC_MAX_AGE_PREFIX: &str = "max-age=";
69
70/// `Cache-Control` `s-maxage=` prefix.
71pub(crate) const CC_S_MAXAGE_PREFIX: &str = "s-maxage=";
72
73/// ASCII digit zero byte (`0`).
74pub(crate) const ASCII_ZERO: u8 = b'0';