77use JsonException ;
88use PDO ;
99use PDOException ;
10- use Psr \SimpleCache \CacheInterface ;
1110use Throwable ;
1211use Yiisoft \Cache \Dependency \TagDependency ;
1312use Yiisoft \Db \Cache \SchemaCache ;
@@ -303,11 +302,8 @@ public function getPdoType($data): int
303302 */
304303 public function refresh (): void
305304 {
306- /* @var $cache CacheInterface */
307- $ cache = $ this ->schemaCache ->getCache ();
308-
309305 if ($ this ->schemaCache ->isEnabled ()) {
310- TagDependency:: invalidate ($ cache , $ this ->getCacheTag ());
306+ $ this -> schemaCache -> invalidate ($ this ->getCacheTag ());
311307 }
312308
313309 $ this ->tableNames = [];
@@ -333,7 +329,7 @@ public function refreshTableSchema(string $name): void
333329 $ this ->tableNames = [];
334330
335331 if ($ this ->schemaCache ->isEnabled ()) {
336- $ this ->schemaCache ->getCache ()-> delete ($ this ->getCacheKey ($ rawName ));
332+ $ this ->schemaCache ->delete ($ this ->getCacheKey ($ rawName ));
337333 }
338334 }
339335
@@ -768,9 +764,9 @@ public function getServerVersion(): string
768764 *
769765 * @throws JsonException
770766 *
771- * @return mixed the cache key.
767+ * @return string the cache key.
772768 */
773- protected function getCacheKey (string $ name )
769+ protected function getCacheKey (string $ name ): string
774770 {
775771 $ key = [
776772 __CLASS__ ,
@@ -779,9 +775,7 @@ protected function getCacheKey(string $name)
779775 $ this ->getRawTableName ($ name ),
780776 ];
781777
782- $ jsonKey = json_encode ($ key , JSON_THROW_ON_ERROR );
783-
784- return md5 ($ jsonKey );
778+ return $ this ->schemaCache ->normalize ($ key );
785779 }
786780
787781 /**
@@ -816,19 +810,15 @@ protected function getCacheTag(): string
816810 */
817811 protected function getTableMetadata (string $ name , string $ type , bool $ refresh = false )
818812 {
819- if ($ this ->schemaCache ->isEnabled () && $ this ->schemaCache ->isExclude ($ name )) {
820- $ schemaCache = $ this ->schemaCache ->getCache ();
821- }
822-
823813 $ rawName = $ this ->getRawTableName ($ name );
824814
825815 if (!isset ($ this ->tableMetadata [$ rawName ])) {
826- $ this ->loadTableMetadataFromCache ($ schemaCache , $ rawName );
816+ $ this ->loadTableMetadataFromCache ($ rawName );
827817 }
828818
829819 if ($ refresh || !array_key_exists ($ type , $ this ->tableMetadata [$ rawName ])) {
830820 $ this ->tableMetadata [$ rawName ][$ type ] = $ this ->{'loadTable ' . ucfirst ($ type )}($ rawName );
831- $ this ->saveTableMetadataToCache ($ schemaCache , $ rawName );
821+ $ this ->saveTableMetadataToCache ($ rawName );
832822 }
833823
834824 return $ this ->tableMetadata [$ rawName ][$ type ];
@@ -910,55 +900,53 @@ protected function normalizePdoRowKeyCase(array $row, bool $multiple): array
910900 /**
911901 * Tries to load and populate table metadata from cache.
912902 *
913- * @param CacheInterface|null $cache
914- * @param string $name
903+ * @param string $rawName
915904 *
916905 * @throws JsonException
917906 */
918- private function loadTableMetadataFromCache (? CacheInterface $ cache , string $ name ): void
907+ private function loadTableMetadataFromCache (string $ rawName ): void
919908 {
920- if ($ cache === null ) {
921- $ this ->tableMetadata [$ name ] = [];
909+ if ($ this -> schemaCache -> isEnabled () === false || $ this -> schemaCache -> isExcluded ( $ rawName ) === true ) {
910+ $ this ->tableMetadata [$ rawName ] = [];
922911
923912 return ;
924913 }
925914
926- $ metadata = $ cache -> get ($ this ->getCacheKey ($ name ));
915+ $ metadata = $ this -> schemaCache -> get ($ this ->getCacheKey ($ rawName ));
927916
928917 if (
929918 !is_array ($ metadata ) ||
930919 !isset ($ metadata ['cacheVersion ' ]) ||
931920 $ metadata ['cacheVersion ' ] !== static ::SCHEMA_CACHE_VERSION
932921 ) {
933- $ this ->tableMetadata [$ name ] = [];
922+ $ this ->tableMetadata [$ rawName ] = [];
934923
935924 return ;
936925 }
937926
938927 unset($ metadata ['cacheVersion ' ]);
939- $ this ->tableMetadata [$ name ] = $ metadata ;
928+ $ this ->tableMetadata [$ rawName ] = $ metadata ;
940929 }
941930
942931 /**
943932 * Saves table metadata to cache.
944933 *
945- * @param CacheInterface|null $cache
946- * @param string $name
934+ * @param string $rawName
947935 *
948936 * @throws JsonException
949937 */
950- private function saveTableMetadataToCache (? CacheInterface $ cache , string $ name ): void
938+ private function saveTableMetadataToCache (string $ rawName ): void
951939 {
952- if ($ cache === null ) {
940+ if ($ this -> schemaCache -> isEnabled () === false || $ this -> schemaCache -> isExcluded ( $ rawName ) === true ) {
953941 return ;
954942 }
955943
956- $ metadata = $ this ->tableMetadata [$ name ];
944+ $ metadata = $ this ->tableMetadata [$ rawName ];
957945
958946 $ metadata ['cacheVersion ' ] = static ::SCHEMA_CACHE_VERSION ;
959947
960- $ cache ->set (
961- $ this ->getCacheKey ($ name ),
948+ $ this -> schemaCache ->set (
949+ $ this ->getCacheKey ($ rawName ),
962950 $ metadata ,
963951 $ this ->schemaCache ->getDuration (),
964952 new TagDependency (['tags ' => $ this ->getCacheTag ()]),
0 commit comments