Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flush to arbitrary file #12

Merged
merged 8 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::{
collections::{hash_map::Entry, HashMap, VecDeque},
future::IntoFuture,
marker::PhantomData,
path::Path,
pin::Pin,
sync::{
mpsc::{channel as oneshot_channel, Sender as OneshotSender},
Expand Down Expand Up @@ -656,6 +657,11 @@ impl SharedBackend {
pub fn flush_cache(&self) {
self.cache.0.flush();
}

/// Flushes the DB to a specific file
pub fn flush_cache_to(&self, cache_path: &Path) {
self.cache.0.flush_to(cache_path);
}
}

impl DatabaseRef for SharedBackend {
Expand Down
9 changes: 8 additions & 1 deletion src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
collections::{BTreeSet, HashMap},
fs,
io::{BufWriter, Write},
path::PathBuf,
path::{Path, PathBuf},
sync::Arc,
};
use url::Url;
Expand Down Expand Up @@ -382,6 +382,13 @@ impl JsonBlockCacheDB {
#[instrument(level = "warn", skip_all, fields(path = ?self.cache_path))]
pub fn flush(&self) {
let Some(path) = &self.cache_path else { return };
self.flush_to(path.as_path());
}

/// Flushes the DB to a specific file
pub fn flush_to(&self, cache_path: &Path) {
let path: &Path = cache_path;

trace!(target: "cache", "saving json cache");

if let Some(parent) = path.parent() {
Expand Down
Loading