Skip to content

Commit 6b95d96

Browse files
committed
graph: Turn IPFS cache into an enum
1 parent 48d5814 commit 6b95d96

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

graph/src/components/link_resolver/ipfs.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,34 @@ use crate::ipfs::RetryPolicy;
2525
use crate::prelude::{LinkResolver as LinkResolverTrait, *};
2626

2727
#[derive(Clone, CheapClone)]
28-
struct Cache {
29-
cache: Arc<Mutex<LruCache<ContentPath, Vec<u8>>>>,
28+
enum Cache {
29+
Memory {
30+
cache: Arc<Mutex<LruCache<ContentPath, Vec<u8>>>>,
31+
},
3032
}
3133

3234
impl Cache {
3335
fn new(capacity: usize) -> Self {
34-
Self {
36+
Self::Memory {
3537
cache: Arc::new(Mutex::new(LruCache::with_capacity(capacity))),
3638
}
3739
}
3840

3941
fn find(&self, path: &ContentPath) -> Option<Vec<u8>> {
40-
self.cache.lock().unwrap().get(path).cloned()
42+
match self {
43+
Cache::Memory { cache } => cache.lock().unwrap().get(path).cloned(),
44+
}
4145
}
4246

4347
fn insert(&self, path: ContentPath, data: Vec<u8>) {
44-
let mut cache = self.cache.lock().unwrap();
48+
match self {
49+
Cache::Memory { cache } => {
50+
let mut cache = cache.lock().unwrap();
4551

46-
if !cache.contains_key(&path) {
47-
cache.insert(path.clone(), data.clone());
52+
if !cache.contains_key(&path) {
53+
cache.insert(path.clone(), data.clone());
54+
}
55+
}
4856
}
4957
}
5058
}

0 commit comments

Comments
 (0)