Skip to content

Commit 0497ddf

Browse files
committed
[Caching] Relativize only project-path options in the cache hash, not every parameter
hashForCacheInvalidation() walked all strict parameters and stripped the cwd prefix from any string that happened to start with it. Scope it to the path-bearing options (paths, autoload paths, bootstrap files) via CACHE_PROJECT_PATH_PARAMETER_NAMES, so relativizing is intentional rather than incidental.
1 parent a64873d commit 0497ddf

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

‎src/Configuration/Parameter/SimpleParameterProvider.php‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ final class SimpleParameterProvider
6262
Option::SKIP,
6363
];
6464

65+
/**
66+
* Absolute-path options anchored to the project before hashing, so a checkout at a different
67+
* path is not read as a changed configuration.
68+
* @var array<Option::*>
69+
*/
70+
private const array CACHE_PROJECT_PATH_PARAMETER_NAMES = [
71+
Option::PATHS,
72+
Option::AUTOLOAD_PATHS,
73+
Option::BOOTSTRAP_FILES,
74+
];
75+
6576
/**
6677
* @var array<string, mixed>
6778
*/
@@ -155,9 +166,21 @@ public static function hashForCacheInvalidation(): string
155166
unset($strictParameters[$ignoredName]);
156167
}
157168

169+
$projectPathPrefix = self::projectPathPrefix();
170+
foreach (self::CACHE_PROJECT_PATH_PARAMETER_NAMES as $pathParameterName) {
171+
if (! isset($strictParameters[$pathParameterName]) || ! is_array($strictParameters[$pathParameterName])) {
172+
continue;
173+
}
174+
175+
$strictParameters[$pathParameterName] = self::relativizeProjectPaths(
176+
$strictParameters[$pathParameterName],
177+
$projectPathPrefix
178+
);
179+
}
180+
158181
ksort($strictParameters);
159182

160-
return sha1(serialize(self::relativizeProjectPaths($strictParameters, self::projectPathPrefix())));
183+
return sha1(serialize($strictParameters));
161184
}
162185

163186
/**
@@ -185,12 +208,8 @@ public static function provideCacheDirectionalParameters(): array
185208
}
186209

187210
/**
188-
* Paths declared in the configuration - analysed paths, autoload and bootstrap files, set
189-
* files - are absolute, so they carry the location of the project into the cache identity.
190-
* Hashed as they are, the cache is bound to one directory: a git worktree, a second
191-
* checkout or a CI cache restored under a different workspace name looks like a changed
192-
* configuration and drops every entry on its first run. Anchored to the project instead,
193-
* they describe the same configuration wherever it is checked out.
211+
* Strips the project prefix off absolute config paths, so the same configuration hashes alike
212+
* across checkouts instead of tying the cache to one directory.
194213
*
195214
* @param mixed[] $parameters
196215
* @return mixed[]

0 commit comments

Comments
 (0)