Skip to content

Commit

Permalink
Use BufReader/BufWriter for data from file cache (#510)
Browse files Browse the repository at this point in the history
* Use BufReader/BufWriter for data from file cache

* formatting

---------

Co-authored-by: user <puh@p>
Co-authored-by: Thang Pham <phamducthang1234@gmail.com>
  • Loading branch information
3 people authored and DOD-101 committed Jul 19, 2024
1 parent e69394f commit bde96bd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions spotify_player/src/state/data.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::io::{BufReader, BufWriter};
use std::{collections::HashMap, path::Path};

use once_cell::sync::Lazy;
Expand Down Expand Up @@ -142,7 +143,7 @@ pub fn store_data_into_file_cache<T: Serialize>(
data: &T,
) -> std::io::Result<()> {
let path = cache_folder.join(format!("{key:?}_cache.json"));
let f = std::fs::File::create(path)?;
let f = BufWriter::new(std::fs::File::create(path)?);
serde_json::to_writer(f, data)?;
Ok(())
}
Expand All @@ -154,7 +155,7 @@ where
let path = cache_folder.join(format!("{key:?}_cache.json"));
if path.exists() {
tracing::info!("Loading {key:?} data from {}...", path.display());
let f = std::fs::File::open(path).expect("path exists");
let f = BufReader::new(std::fs::File::open(path).expect("path exists"));
match serde_json::from_reader(f) {
Ok(data) => {
tracing::info!("Successfully loaded {key:?} data!");
Expand Down

0 comments on commit bde96bd

Please sign in to comment.