Skip to content

Commit b267e47

Browse files
committed
Refactor compression config to models module
Moved the `CompressionConfig` struct and related constants from `desktop.rs` to `models.rs` for better modularity and reuse. Removed redundant imports and definitions in `lib.rs` and `desktop.rs`.
1 parent 63051de commit b267e47

3 files changed

Lines changed: 24 additions & 27 deletions

File tree

src/desktop.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ use tauri::{plugin::PluginApi, AppHandle, Runtime};
1414
use crate::models::*;
1515
use crate::Error;
1616

17-
// The size threshold in bytes after which compression will be applied
18-
const COMPRESSION_THRESHOLD: usize = 1024; // 1KB
19-
2017
// Store the value and its optional expiry time in a single struct for better organization
2118
#[derive(Clone, Serialize, Deserialize)]
2219
struct CacheEntry {
@@ -25,27 +22,6 @@ struct CacheEntry {
2522
is_compressed: Option<bool>,
2623
}
2724

28-
/// Enhanced configuration for cache compression
29-
#[derive(Clone, Serialize, Deserialize, Debug)]
30-
pub struct CompressionConfig {
31-
/// Enable or disable compression
32-
pub enabled: bool,
33-
/// Compression level (0-9, where 0 is no compression and 9 is max compression)
34-
pub level: u32,
35-
/// Threshold in bytes after which compression is applied
36-
pub threshold: usize,
37-
}
38-
39-
impl Default for CompressionConfig {
40-
fn default() -> Self {
41-
Self {
42-
enabled: false,
43-
level: 6, // Default compression level
44-
threshold: COMPRESSION_THRESHOLD,
45-
}
46-
}
47-
}
48-
4925
// Initialize the cache with a custom configuration
5026
pub fn init_with_config<R: Runtime, C: DeserializeOwned>(
5127
app: &AppHandle<R>,

src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ use desktop::Cache;
2121
#[cfg(mobile)]
2222
use mobile::Cache;
2323

24-
#[cfg(desktop)]
25-
pub use desktop::CompressionConfig;
26-
2724
/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the cache APIs.
2825
pub trait CacheExt<R: Runtime> {
2926
fn cache(&self) -> &Cache<R>;

src/models.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use serde::{de::DeserializeOwned, Deserialize, Serialize};
22

3+
// The size threshold in bytes after which compression will be applied
4+
pub const COMPRESSION_THRESHOLD: usize = 1024; // 1KB
5+
36
/// Options for setting an item in the cache
47
#[derive(Debug, Clone, Deserialize, Serialize)]
58
#[serde(rename_all = "camelCase")]
@@ -111,6 +114,27 @@ pub struct BooleanResponse {
111114
#[serde(rename_all = "camelCase")]
112115
pub struct EmptyResponse {}
113116

117+
/// Enhanced configuration for cache compression
118+
#[derive(Clone, Serialize, Deserialize, Debug)]
119+
pub struct CompressionConfig {
120+
/// Enable or disable compression
121+
pub enabled: bool,
122+
/// Compression level (0-9, where 0 is no compression and 9 is max compression)
123+
pub level: u32,
124+
/// Threshold in bytes after which compression is applied
125+
pub threshold: usize,
126+
}
127+
128+
impl Default for CompressionConfig {
129+
fn default() -> Self {
130+
Self {
131+
enabled: false,
132+
level: 6, // Default compression level
133+
threshold: COMPRESSION_THRESHOLD,
134+
}
135+
}
136+
}
137+
114138
/// Configuration options for the cache plugin
115139
#[derive(Debug, Clone, Deserialize, Serialize)]
116140
#[serde(rename_all = "camelCase")]

0 commit comments

Comments
 (0)