use super::*;
#[derive(Clone, Data, Debug, Eq, PartialEq)]
pub struct CachedValue {
#[get(type(copy))]
pub(crate) status_code: usize,
pub(crate) headers: Vec<(String, String)>,
pub(crate) body: Vec<u8>,
#[get(type(copy))]
pub(crate) stored_at_ms: u64,
}
pub(crate) struct CachedHttp11Wire {
pub(crate) without_diag: Vec<u8>,
pub(crate) with_diag_prefix: Vec<u8>,
pub(crate) with_diag_suffix: Vec<u8>,
}
pub(crate) struct CacheEntry {
pub(crate) value: CachedValue,
pub(crate) expires_at_ms: u64,
pub(crate) footprint_bytes: usize,
pub(crate) wire_cache: OnceLock<Option<Box<CachedHttp11Wire>>>,
}
pub(crate) struct InFlightSlot {
pub(crate) notify: Notify,
pub(crate) result: Mutex<Option<Option<CachedValue>>>,
}
#[derive(Clone, Data, Debug, Eq, PartialEq)]
pub struct CacheConfig {
#[get(type(copy))]
pub(crate) default_ttl_ms: u64,
#[get(type(copy))]
pub(crate) max_entries: usize,
#[get(type(copy))]
pub(crate) max_bytes: usize,
#[get(type(copy))]
pub(crate) max_entry_bytes: usize,
#[get(type(copy))]
pub(crate) bypass_authenticated: bool,
#[get(type(copy))]
pub(crate) emit_diagnostic_headers: bool,
}
#[repr(align(64))]
pub(crate) struct CacheShard {
pub(crate) map: RwLock<HashMapXxHash3_64<String, Arc<CacheEntry>>>,
}
pub(crate) struct ShardedMemoryCacheInner {
pub(crate) config: CacheConfig,
pub(crate) entry_count: AtomicUsize,
pub(crate) total_bytes: AtomicUsize,
pub(crate) min_expires_at_ms: AtomicU64,
pub(crate) shards: Box<[CacheShard; CACHE_SHARD_COUNT]>,
pub(crate) inflight: InFlightShardArray,
}
#[derive(Clone)]
pub struct ShardedMemoryCache {
pub(crate) inner: Arc<ShardedMemoryCacheInner>,
}
#[derive(Clone)]
pub struct CachePlugin {
pub(crate) config: CacheConfig,
pub(crate) store: Arc<dyn CacheStore>,
pub(crate) local_store: Option<ShardedMemoryCache>,
}
#[derive(Clone, Copy, Debug, Default)]
#[hyperlane::request_middleware(-80)]
pub struct CacheRequestHook;
#[derive(Clone, Copy, Debug, Default)]
#[hyperlane::response_middleware(-65)]
pub struct CacheResponseHook;