@@ -959,19 +959,23 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
959959
960960 if ('cache ' === $ type ) {
961961 foreach ($ stores as $ name => $ store ) {
962+ $ distanceCalculatorDefinition = new Definition (DistanceCalculator::class);
963+ $ distanceCalculatorDefinition ->setLazy (true );
964+
965+ $ container ->setDefinition ('ai.store.distance_calculator. ' .$ name , $ distanceCalculatorDefinition );
966+
962967 $ arguments = [
963968 new Reference ($ store ['service ' ]),
964- new Definition (DistanceCalculator::class ),
969+ new Reference ( ' ai.store.distance_calculator. ' . $ name ),
965970 $ store ['cache_key ' ] ?? $ name ,
966971 ];
967972
968973 if (\array_key_exists ('strategy ' , $ store ) && null !== $ store ['strategy ' ]) {
969- if (! $ container -> hasDefinition ( ' ai.store.distance_calculator. ' . $ name )) {
970- $ distanceCalculatorDefinition = new Definition (DistanceCalculator::class );
971- $ distanceCalculatorDefinition ->setArgument (0 , DistanceStrategy::from ($ store ['strategy ' ]));
974+ $ distanceCalculatorDefinition = new Definition (DistanceCalculator::class);
975+ $ distanceCalculatorDefinition-> setLazy ( true );
976+ $ distanceCalculatorDefinition ->setArgument (0 , DistanceStrategy::from ($ store ['strategy ' ]));
972977
973- $ container ->setDefinition ('ai.store.distance_calculator. ' .$ name , $ distanceCalculatorDefinition );
974- }
978+ $ container ->setDefinition ('ai.store.distance_calculator. ' .$ name , $ distanceCalculatorDefinition );
975979
976980 $ arguments [1 ] = new Reference ('ai.store.distance_calculator. ' .$ name );
977981 }
@@ -1015,8 +1019,7 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
10151019 $ httpClient = new Definition (HttpClientInterface::class);
10161020 $ httpClient
10171021 ->setFactory ([HttpClient::class, 'createForBaseUri ' ])
1018- ->setArguments ([$ store ['dsn ' ]])
1019- ;
1022+ ->setArguments ([$ store ['dsn ' ]]);
10201023 }
10211024
10221025 $ definition = new Definition (ClickHouseStore::class);
@@ -1028,8 +1031,7 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
10281031 $ store ['table ' ],
10291032 ])
10301033 ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
1031- ->addTag ('ai.store ' )
1032- ;
1034+ ->addTag ('ai.store ' );
10331035
10341036 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
10351037 $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ name );
0 commit comments