@@ -42,13 +42,22 @@ public static function loadFromFile(string $file, string $registry_name): string
4242 if ($ content === false ) {
4343 throw new WrongUsageException ("Failed to read artifact config file: {$ file }" );
4444 }
45- $ data = match (pathinfo ($ file , PATHINFO_EXTENSION )) {
46- 'json ' => json_decode ($ content , true ),
47- 'yml ' , 'yaml ' => Yaml::parse ($ content ),
48- default => throw new WrongUsageException ("Unsupported artifact config file format: {$ file }" ),
49- };
50- if (!is_array ($ data )) {
51- throw new WrongUsageException ("Invalid JSON format in artifact config file: {$ file }" );
45+ // use cache to skip redundant parsing
46+ $ data = ConfigCache::get ($ content );
47+ if ($ data !== null ) {
48+ logger ()->debug ("Config cache hit: {$ file }" );
49+ } else {
50+ $ data = match (pathinfo ($ file , PATHINFO_EXTENSION )) {
51+ 'json ' => json_decode ($ content , true ),
52+ 'yml ' , 'yaml ' => extension_loaded ('yaml ' ) ? yaml_parse ($ content ) : Yaml::parse ($ content ),
53+ default => throw new WrongUsageException ("Unsupported artifact config file format: {$ file }" ),
54+ };
55+ if (!is_array ($ data )) {
56+ throw new WrongUsageException ("Invalid JSON format in artifact config file: {$ file }" );
57+ }
58+ if (is_array ($ data )) {
59+ ConfigCache::set ($ content , $ data );
60+ }
5261 }
5362 ConfigValidator::validateAndLintArtifacts (basename ($ file ), $ data );
5463 foreach ($ data as $ artifact_name => $ config ) {
@@ -68,6 +77,16 @@ public static function getAll(): array
6877 return self ::$ artifact_configs ;
6978 }
7079
80+ /**
81+ * Restore artifact configs from cache without re-parsing YAML files.
82+ *
83+ * @internal used by Registry cache layer only
84+ */
85+ public static function _restoreFromCache (array $ configs ): void
86+ {
87+ self ::$ artifact_configs = array_merge (self ::$ artifact_configs , $ configs );
88+ }
89+
7190 /**
7291 * Get the configuration for a specific artifact by name.
7392 *
0 commit comments