Skip to main content

rskit_cache/adapters/fs/
config.rs

1use std::path::PathBuf;
2
3use serde::{Deserialize, Serialize};
4
5pub(crate) const DEFAULT_MAX_ENTRY_BYTES: u64 = 16 * 1024 * 1024;
6
7/// Filesystem cache configuration.
8///
9/// The root path is supplied when registering the adapter because it is a
10/// deployment concern owned by the composition boundary, not common cache
11/// selection configuration.
12#[derive(Debug, Clone, Deserialize, Serialize)]
13pub struct FileCacheConfig {
14    /// Root directory used to store cache entries.
15    pub root: PathBuf,
16    /// Optional prefix prepended to every key.
17    pub key_prefix: Option<String>,
18    /// Maximum serialized cache-entry size accepted by reads and writes.
19    #[serde(default = "default_max_entry_bytes")]
20    pub max_entry_bytes: u64,
21}
22
23impl FileCacheConfig {
24    /// Create filesystem cache configuration rooted at `root`.
25    #[must_use]
26    pub fn new(root: impl Into<PathBuf>) -> Self {
27        Self {
28            root: root.into(),
29            key_prefix: None,
30            max_entry_bytes: DEFAULT_MAX_ENTRY_BYTES,
31        }
32    }
33}
34
35const fn default_max_entry_bytes() -> u64 {
36    DEFAULT_MAX_ENTRY_BYTES
37}