File tree Expand file tree Collapse file tree
graph/src/components/link_resolver Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,26 +25,34 @@ use crate::ipfs::RetryPolicy;
2525use 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
3234impl 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}
You can’t perform that action at this time.
0 commit comments