hyperlane-plugin-cache 22.14.0

A 64-way sharded bounded in-memory and HTTP response cache plugin for the Hyperlane framework with TTL, byte-budget eviction, single-flight stampede coalescing, pluggable CacheStore traits, and RFC Cache-Control/Vary/Age/X-Cache handling.
Documentation
/// Diagnostic header indicating cache lookup outcome (`HIT`, `MISS`, or `BYPASS`).
pub const HEADER_X_CACHE: &str = "x-cache";

/// `X-Cache` value emitted when served directly from cache.
pub const X_CACHE_HIT: &str = "HIT";

/// `X-Cache` value emitted when computed by the origin handler.
pub const X_CACHE_MISS: &str = "MISS";

/// `X-Cache` value emitted when caching is bypassed by policy or headers.
pub const X_CACHE_BYPASS: &str = "BYPASS";

/// Default response cache TTL in milliseconds (60 seconds).
pub const DEFAULT_CACHE_TTL_MS: u64 = 60_000;

/// Default maximum cached response count across all shards.
pub const DEFAULT_CACHE_MAX_ENTRIES: usize = 16_384;

/// Default maximum total cached byte budget (64 MiB).
pub const DEFAULT_CACHE_MAX_BYTES: usize = 64 * 1024 * 1024;

/// Default maximum single response body eligible for HTTP response caching (1 MiB).
pub const DEFAULT_CACHE_MAX_ENTRY_BYTES: usize = 1024 * 1024;

/// Number of independent cache shards (`64`, power of two).
pub(crate) const CACHE_SHARD_COUNT: usize = 64;

/// Maximum decimal digit buffer capacity for stack formatting a `u64` `Age` header value.
pub(crate) const AGE_STACK_BUF_LEN: usize = 20;

/// Maximum prebuilt HTTP/1.1 cache hit response length assembled on the stack without heap allocation.
pub(crate) const CACHE_WIRE_STACK_CAP: usize = 4096;

/// FNV-1a 64-bit offset basis used for fast cache shard selection.
pub(crate) const CACHE_FNV1A_OFFSET_BASIS: u64 = 0xcbf2_9ce4_8422_2325;

/// FNV-1a 64-bit prime multiplier used for fast cache shard selection.
pub(crate) const CACHE_FNV1A_PRIME: u64 = 0x0000_0100_0000_01b3;

/// Prebuilt HTTP/1.1 diagnostic header block inserted before the decimal `Age` value.
pub(crate) const CACHE_WIRE_DIAG_PREFIX: &[u8] = b"x-cache: HIT\r\nage: ";

/// CRLF separator terminating HTTP/1.1 headers.
pub(crate) const CACHE_WIRE_CRLF: &[u8] = b"\r\n";

/// Double-CRLF sequence separating HTTP/1.1 headers from the response body.
pub(crate) const CACHE_WIRE_HEADER_END: &[u8] = b"\r\n\r\n";

/// Context attribute key passing the computed HTTP cache key from request hook to response hook.
pub(crate) const ATTR_HTTP_CACHE_KEY: &str = "hyperlane_plugin_cache_key";

/// `Cache-Control` directive prohibiting storing a response.
pub(crate) const CC_NO_STORE: &str = "no-store";

/// `Cache-Control` directive prohibiting unvalidated reuse.
pub(crate) const CC_NO_CACHE: &str = "no-cache";

/// `Cache-Control` directive marking a response private to a single user.
pub(crate) const CC_PRIVATE: &str = "private";

/// `Cache-Control` `max-age=` prefix.
pub(crate) const CC_MAX_AGE_PREFIX: &str = "max-age=";

/// `Cache-Control` `s-maxage=` prefix.
pub(crate) const CC_S_MAXAGE_PREFIX: &str = "s-maxage=";