File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ pub(crate) fn get_relative_path(
5555#[ derive( Clone ) ]
5656pub struct Data {
5757 pub ( crate ) work_dir : PathBuf ,
58- cache : Cache < PathBuf , GraphWithVectors > ,
58+ pub ( crate ) cache : Cache < PathBuf , GraphWithVectors > ,
5959 pub ( crate ) create_index : bool ,
6060 pub ( crate ) embedding_conf : Option < EmbeddingConf > ,
6161}
@@ -414,6 +414,14 @@ pub(crate) mod data_tests {
414414 sleep ( Duration :: from_secs ( 3 ) ) . await ;
415415 assert ! ( !data. cache. contains_key( Path :: new( "test_g" ) ) ) ;
416416 assert ! ( !data. cache. contains_key( Path :: new( "test_g2" ) ) ) ;
417+ // FIXME: this test is not doing anything because calling cache.contains_key() runs
418+ // any pending evictions. To actually test it we need this assertion:
419+ // assert_eq!(data.cache.entry_count(), 0);
420+ // Which currently does not work because the server task to trigger evictions is not running
421+ // in this context. The problem is if we do run it by creating a server and calling
422+ // server.start() the server gets consumed and we loose access to the cache to be able to run
423+ // the check. If rework the server implementation and this becomes feasible we should change
424+ // this test
417425 }
418426
419427 #[ tokio:: test]
Original file line number Diff line number Diff line change @@ -200,6 +200,16 @@ impl GraphServer {
200200 self . data . vectorise_all_graphs_that_are_not ( ) . await ?;
201201 let work_dir = self . data . work_dir . clone ( ) ;
202202
203+ // Otherwise evictions are only triggered when the cache is actively touched
204+ let cache_clone = self . data . cache . clone ( ) ;
205+ tokio:: spawn ( async move {
206+ let mut interval = tokio:: time:: interval ( std:: time:: Duration :: from_secs ( 1 ) ) ;
207+ loop {
208+ interval. tick ( ) . await ;
209+ cache_clone. run_pending_tasks ( ) . await ;
210+ }
211+ } ) ;
212+
203213 // it is important that this runs after algorithms have been pushed to PLUGIN_ALGOS static variable
204214 let app = self
205215 . generate_endpoint ( tp. clone ( ) . map ( |tp| tp. tracer ( tracer_name) ) )
You can’t perform that action at this time.
0 commit comments