@@ -960,19 +960,23 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
960960
961961 if ('cache ' === $ type ) {
962962 foreach ($ stores as $ name => $ store ) {
963+ $ distanceCalculatorDefinition = new Definition (DistanceCalculator::class);
964+ $ distanceCalculatorDefinition ->setLazy (true );
965+
966+ $ container ->setDefinition ('ai.store.distance_calculator. ' .$ name , $ distanceCalculatorDefinition );
967+
963968 $ arguments = [
964969 new Reference ($ store ['service ' ]),
965- new Definition (DistanceCalculator::class ),
970+ new Reference ( ' ai.store.distance_calculator. ' . $ name ),
966971 $ store ['cache_key ' ] ?? $ name ,
967972 ];
968973
969974 if (\array_key_exists ('strategy ' , $ store ) && null !== $ store ['strategy ' ]) {
970- if (! $ container -> hasDefinition ( ' ai.store.distance_calculator. ' . $ name )) {
971- $ distanceCalculatorDefinition = new Definition (DistanceCalculator::class );
972- $ distanceCalculatorDefinition ->setArgument (0 , DistanceStrategy::from ($ store ['strategy ' ]));
975+ $ distanceCalculatorDefinition = new Definition (DistanceCalculator::class);
976+ $ distanceCalculatorDefinition-> setLazy ( true );
977+ $ distanceCalculatorDefinition ->setArgument (0 , DistanceStrategy::from ($ store ['strategy ' ]));
973978
974- $ container ->setDefinition ('ai.store.distance_calculator. ' .$ name , $ distanceCalculatorDefinition );
975- }
979+ $ container ->setDefinition ('ai.store.distance_calculator. ' .$ name , $ distanceCalculatorDefinition );
976980
977981 $ arguments [1 ] = new Reference ('ai.store.distance_calculator. ' .$ name );
978982 }
@@ -1016,8 +1020,7 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
10161020 $ httpClient = new Definition (HttpClientInterface::class);
10171021 $ httpClient
10181022 ->setFactory ([HttpClient::class, 'createForBaseUri ' ])
1019- ->setArguments ([$ store ['dsn ' ]])
1020- ;
1023+ ->setArguments ([$ store ['dsn ' ]]);
10211024 }
10221025
10231026 $ definition = new Definition (ClickHouseStore::class);
@@ -1029,8 +1032,7 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
10291032 $ store ['table ' ],
10301033 ])
10311034 ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
1032- ->addTag ('ai.store ' )
1033- ;
1035+ ->addTag ('ai.store ' );
10341036
10351037 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
10361038 $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ name );
0 commit comments