Skip to main content

micromegas_object_cache/
backend.rs

1use async_trait::async_trait;
2use bytes::Bytes;
3
4/// Hints the backend's fill priority: prefetch fills should not evict hot
5/// demand data from a bounded cache tier.
6#[derive(Copy, Clone, Debug, PartialEq, Eq)]
7pub enum FillHint {
8    Demand,
9    Prefetch,
10}
11
12/// Point-in-time disk write-path counters (cumulative since process start).
13/// foyer-independent so the trait stays buildable without the `foyer`
14/// feature; `None` for backends with no disk tier (e.g. in-memory).
15#[derive(Clone, Copy, Debug, Default)]
16pub struct BackendDiskStats {
17    pub write_bytes: u64,
18    pub read_bytes: u64,
19    pub write_ios: u64,
20    pub read_ios: u64,
21}
22
23#[async_trait]
24pub trait RangeCacheBackend: Send + Sync {
25    async fn get(&self, key: &str) -> Option<Bytes>;
26    async fn put(&self, key: String, value: Bytes, hint: FillHint);
27
28    /// Disk write-path counters, for the saturation monitor's per-second
29    /// gauges. Defaulted to `None` so backends without a disk tier (e.g.
30    /// `MemoryBackend`) need no override.
31    fn disk_stats(&self) -> Option<BackendDiskStats> {
32        None
33    }
34}