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 deployment concern owned by the composition boundary,
10/// not common cache selection configuration.
11#[derive(Debug, Clone, Deserialize, Serialize)]
12pub struct FileCacheConfig {
13    /// Root directory used to store cache entries.
14    pub root: PathBuf,
15    /// Optional prefix prepended to every key.
16    pub key_prefix: Option<String>,
17    /// Maximum serialized cache-entry size accepted by reads and writes.
18    #[serde(default = "default_max_entry_bytes")]
19    pub max_entry_bytes: u64,
20}
21
22impl FileCacheConfig {
23    /// Create filesystem cache configuration rooted at `root`.
24    #[must_use]
25    pub fn new(root: impl Into<PathBuf>) -> Self {
26        Self {
27            root: root.into(),
28            key_prefix: None,
29            max_entry_bytes: DEFAULT_MAX_ENTRY_BYTES,
30        }
31    }
32}
33
34const fn default_max_entry_bytes() -> u64 {
35    DEFAULT_MAX_ENTRY_BYTES
36}