Skip to content
Merged
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
34 changes: 31 additions & 3 deletions rust/cache/src/foyer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ where
})
}

pub fn insert_to_disk(&self, key: K, value: V) {
#[allow(dead_code)]
fn insert_to_disk(&self, key: K, value: V) {
self.cache.storage_writer(key).insert(value);
}
}
Expand All @@ -466,8 +467,6 @@ where
async fn insert(&self, key: K, value: V) {
let _stopwatch = Stopwatch::new(&self.insert_latency);
self.cache.insert(key.clone(), value.clone());
// Also insert to the disk cache.
self.insert_to_disk(key, value);
}

async fn remove(&self, key: &K) {
Expand Down Expand Up @@ -692,7 +691,9 @@ mod test {
}
}

// TODO(@codetheweb): this test should not panic once we write to disk cache upon insert to memory cache
#[tokio::test]
#[should_panic]
async fn test_foyer_hybrid_cache_can_recover() {
let dir = tempfile::tempdir()
.expect("To be able to create temp path")
Expand Down Expand Up @@ -767,4 +768,31 @@ mod test {
.expect("Value should not be None");
assert_eq!(value, large_value);
}

#[tokio::test]
async fn test_inserted_key_immediately_available() {
let dir = tempfile::tempdir()
.expect("To be able to create temp path")
.path()
.to_str()
.expect("To be able to parse path")
.to_string();
let cache = FoyerCacheConfig {
dir: Some(dir.clone()),
flush: true,
..Default::default()
}
.build_hybrid_test::<String, String>()
.await
.unwrap();

cache.insert("key1".to_string(), "foo".to_string()).await;

let value = cache
.get(&"key1".to_string())
.await
.expect("Expected to be able to get value")
.expect("Value should not be None");
assert_eq!(value, "foo");
}
}
Loading