reflex/cache/
types.rs

1/// Response header used to report cache status.
2pub const REFLEX_STATUS_HEADER: &str = "X-Reflex-Status";
3/// Health value for status endpoints.
4pub const REFLEX_STATUS_HEALTHY: &str = "healthy";
5/// Ready value for status endpoints.
6pub const REFLEX_STATUS_READY: &str = "ready";
7/// Not-ready value for status endpoints.
8pub const REFLEX_STATUS_NOT_READY: &str = "not_ready";
9/// Stored value for status endpoints.
10pub const REFLEX_STATUS_STORED: &str = "stored";
11/// Error value for status endpoints.
12pub const REFLEX_STATUS_ERROR: &str = "error";
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
15/// High-level cache status used for metrics and response headers.
16pub enum ReflexStatus {
17    /// L1 exact-match hit.
18    HitL1Exact,
19    /// L2 semantic hit.
20    HitL2Semantic,
21    /// L3 verified hit.
22    HitL3Verified,
23    /// Cache miss.
24    Miss,
25}
26
27impl ReflexStatus {
28    #[inline]
29    /// Returns a stable string suitable for the `X-Reflex-Status` header.
30    pub fn as_header_value(&self) -> &'static str {
31        match self {
32            ReflexStatus::HitL1Exact => "HIT_L1_EXACT",
33            ReflexStatus::HitL2Semantic => "HIT_L2_SEMANTIC",
34            ReflexStatus::HitL3Verified => "HIT_L3_VERIFIED",
35            ReflexStatus::Miss => "MISS",
36        }
37    }
38
39    #[inline]
40    /// Returns `true` if this is not a miss.
41    pub fn is_hit(&self) -> bool {
42        !matches!(self, ReflexStatus::Miss)
43    }
44}
45
46impl std::fmt::Display for ReflexStatus {
47    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48        write!(f, "{}", self.as_header_value())
49    }
50}