Skip to content

Commit f1454b7

Browse files
committed
Refactor cache value type in desktop.rs
Introduced type aliases for cache value types to improve readability and maintainability. Updated the `value_cache` field in the `Cache` struct to use the new `ThreadSafeCacheMap` alias.
1 parent 1fe5e3f commit f1454b7

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/desktop.rs

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

17+
// Define a type alias for the complex cache value type
18+
type CacheValueEntry = (serde_json::Value, Option<u64>);
19+
type CacheValueMap = HashMap<String, CacheValueEntry>;
20+
type ThreadSafeCacheMap = Arc<Mutex<CacheValueMap>>;
21+
1722
// Store the value and its optional expiry time in a single struct for better organization
1823
#[derive(Clone, Serialize, Deserialize)]
1924
struct CacheEntry {
@@ -52,7 +57,7 @@ pub struct Cache<R: Runtime> {
5257
cleanup_interval: u64,
5358
file_mutex: Arc<Mutex<()>>,
5459
compression: CompressionConfig,
55-
value_cache: Arc<Mutex<HashMap<String, (serde_json::Value, Option<u64>)>>>,
60+
value_cache: ThreadSafeCacheMap,
5661
}
5762

5863
impl<R: Runtime> Cache<R> {

0 commit comments

Comments
 (0)