@@ -71,10 +71,11 @@ pub struct MoonrakerConnection {
7171 outbound_event_sender : Sender < Arc < OutboundMessage > > ,
7272 outbound_event_listener : Receiver < Arc < OutboundMessage > > ,
7373 incrementing_id : Mutex < u32 > ,
74+ preconfigured_cache : Option < Cache > ,
7475}
7576
7677impl MoonrakerConnection {
77- pub fn new ( host : & str , port : u16 ) -> Self {
78+ pub fn new ( host : & str , port : u16 , preconfigured_cache : Option < Cache > ) -> Self {
7879 let host = format ! ( "{}:{}" , host, port) ;
7980
8081 let req = Request :: builder ( )
@@ -107,6 +108,7 @@ impl MoonrakerConnection {
107108 outbound_event_sender : outbound_event_sender,
108109 outbound_event_listener : outbound_event_listener,
109110 incrementing_id : Mutex :: new ( 1 ) ,
111+ preconfigured_cache
110112 }
111113 }
112114
@@ -126,7 +128,7 @@ impl MoonrakerConnection {
126128 . expect ( "Failed to internally send a disconnect event" ) ;
127129 let reader;
128130 let writer;
129- let cache = Arc :: new ( Mutex :: new ( Cache :: new ( ) ) ) ;
131+ let cache = Arc :: new ( Mutex :: new ( self . preconfigured_cache . clone ( ) . unwrap_or_default ( ) ) ) ;
130132
131133 match self . reconnect ( ) . await {
132134 Ok ( ( r, w) ) => {
0 commit comments