File tree Expand file tree Collapse file tree 1 file changed +15
-7
lines changed
graph/src/components/link_resolver Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -25,26 +25,34 @@ use crate::ipfs::RetryPolicy;
25
25
use crate :: prelude:: { LinkResolver as LinkResolverTrait , * } ;
26
26
27
27
#[ 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
+ } ,
30
32
}
31
33
32
34
impl Cache {
33
35
fn new ( capacity : usize ) -> Self {
34
- Self {
36
+ Self :: Memory {
35
37
cache : Arc :: new ( Mutex :: new ( LruCache :: with_capacity ( capacity) ) ) ,
36
38
}
37
39
}
38
40
39
41
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
+ }
41
45
}
42
46
43
47
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 ( ) ;
45
51
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
+ }
48
56
}
49
57
}
50
58
}
You can’t perform that action at this time.
0 commit comments