aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorMalte Voos <git@mal.tc>2026-01-01 19:26:01 +0100
committerMalte Voos <git@mal.tc>2026-01-04 00:38:38 +0100
commitc8b942b1fbe8fdab1db0e0f56d3ed86a7486b578 (patch)
treecf344838c96ad9bd7bd97d0216c43d6a858f4a60 /src/util
parent80a1c8234fc5b6f56bd1f2df4e6118e57631f523 (diff)
downloadlleap-main.tar.gz
lleap-main.zip
cache extracted subtitles & deepl translationsHEADmain
Diffstat (limited to 'src/util')
-rw-r--r--src/util/cache.rs24
-rw-r--r--src/util/mod.rs2
2 files changed, 26 insertions, 0 deletions
diff --git a/src/util/cache.rs b/src/util/cache.rs
new file mode 100644
index 0000000..6e4672f
--- /dev/null
+++ b/src/util/cache.rs
@@ -0,0 +1,24 @@
+use std::env;
+
+use cached::DiskCache;
+use directories::BaseDirs;
+use serde::{Serialize, de::DeserializeOwned};
+
+pub fn make_cache<K, V>(name: &str) -> DiskCache<K, V>
+where
+ K: ToString,
+ V: Serialize + DeserializeOwned,
+{
+ let dir = match BaseDirs::new() {
+ Some(base_dirs) => base_dirs.cache_dir().join("lleap"),
+ None => env::current_dir()
+ .expect("unable to determine current directory")
+ .join("lleap_cache"),
+ };
+
+ DiskCache::new(name)
+ .set_disk_directory(dir)
+ .set_sync_to_disk_on_cache_change(true)
+ .build()
+ .expect("unable to open disk cache")
+}
diff --git a/src/util/mod.rs b/src/util/mod.rs
index 4d19eff..2098a35 100644
--- a/src/util/mod.rs
+++ b/src/util/mod.rs
@@ -1,3 +1,5 @@
+mod cache;
mod tracker;
+pub use cache::make_cache;
pub use tracker::Tracker;