tauri_plugin_redb_cache/
config.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct CacheConfig {
8 pub http_ttl_ms: u64,
10 pub image_ttl_ms: u64,
12 pub memory_cache_size: usize,
14 pub compress_threshold: usize,
16 pub cleanup_interval_secs: u64,
18 pub db_filename: String,
20}
21
22impl Default for CacheConfig {
23 fn default() -> Self {
24 Self {
25 http_ttl_ms: 15 * 24 * 60 * 60 * 1000, image_ttl_ms: 15 * 24 * 60 * 60 * 1000, memory_cache_size: 100,
28 compress_threshold: 1024, cleanup_interval_secs: 3600, db_filename: "cache.redb".to_string(),
31 }
32 }
33}
34
35#[derive(Default)]
37pub struct Builder {
38 pub(crate) config: CacheConfig,
39}
40
41impl Builder {
42 pub fn new() -> Self {
44 Self::default()
45 }
46
47 pub fn http_ttl_ms(mut self, ttl: u64) -> Self {
49 self.config.http_ttl_ms = ttl;
50 self
51 }
52
53 pub fn image_ttl_ms(mut self, ttl: u64) -> Self {
55 self.config.image_ttl_ms = ttl;
56 self
57 }
58
59 pub fn memory_cache_size(mut self, size: usize) -> Self {
61 self.config.memory_cache_size = size;
62 self
63 }
64
65 pub fn compress_threshold(mut self, threshold: usize) -> Self {
67 self.config.compress_threshold = threshold;
68 self
69 }
70
71 pub fn cleanup_interval_secs(mut self, interval: u64) -> Self {
73 self.config.cleanup_interval_secs = interval;
74 self
75 }
76
77 pub fn db_filename(mut self, filename: impl Into<String>) -> Self {
79 self.config.db_filename = filename.into();
80 self
81 }
82}