ferrite_config/
cache.rs

1use crate::{ConfigError, Result};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct CacheConfig {
6    pub preload_count: usize,
7    pub max_memory_items: usize,
8    pub worker_threads: usize,
9}
10
11impl Default for CacheConfig {
12    fn default() -> Self {
13        Self { preload_count: 2, max_memory_items: 100, worker_threads: 8 }
14    }
15}
16impl CacheConfig {
17    pub fn validate(&self) -> Result<()> {
18        if self.worker_threads == 0 {
19            return Err(ConfigError::ValidationError(
20                "Cache worker_threads must be at least 1.".to_string(),
21            ));
22        }
23        if self.max_memory_items == 0 {
24            return Err(ConfigError::ValidationError(
25                "Cache max_memory_items must be at least 1.".to_string(),
26            ));
27        }
28        // preload_count can be 0 if no preloading is desired.
29        Ok(())
30    }
31}