patronus_ark/cache/
config.rs1use std::fmt;
3use std::path::PathBuf;
4use std::time::Duration;
5
6use super::{MemoryCacheConfig, WriteBehindConfig};
7
8#[derive(Debug, Clone)]
9pub struct ExactCacheConfig {
10 pub memory: MemoryCacheConfig,
11 pub persistent: Option<PersistentCacheConfig>,
12 pub entry_ttl: Duration,
13}
14
15impl Default for ExactCacheConfig {
16 fn default() -> Self {
17 Self {
18 memory: MemoryCacheConfig::default(),
19 persistent: None,
20 entry_ttl: Duration::from_secs(30 * 24 * 60 * 60),
21 }
22 }
23}
24
25#[derive(Clone)]
26pub struct CacheEncryptionConfig {
27 pub key: [u8; 32],
28}
29
30impl CacheEncryptionConfig {
31 pub fn from_key(key: [u8; 32]) -> Self {
32 Self { key }
33 }
34}
35
36impl fmt::Debug for CacheEncryptionConfig {
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 f.debug_struct("CacheEncryptionConfig")
39 .field("key", &"<redacted>")
40 .finish()
41 }
42}
43
44#[derive(Debug, Clone)]
45pub struct PersistentCacheConfig {
46 pub storage_location: PathBuf,
47 pub write_mode: CacheWriteMode,
48 pub write_behind: WriteBehindConfig,
49 pub encryption: Option<CacheEncryptionConfig>,
50}
51
52#[derive(Debug, Clone, Copy, PartialEq, Eq)]
53pub enum CacheWriteMode {
54 WriteThrough,
55 Async,
56}