Skip to content

Commit 740ec29

Browse files
janedbalondrejmirtes
authored andcommitted
ResultCache: configurable days causing cache skip
1 parent 29cb09b commit 740ec29

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

Diff for: conf/config.neon

+2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ parameters:
125125
earlyTerminatingMethodCalls: []
126126
earlyTerminatingFunctionCalls: []
127127
resultCachePath: %tmpDir%/resultCache.php
128+
resultCacheSkipIfOlderThanDays: 7
128129
resultCacheChecksProjectExtensionFilesDependencies: false
129130
dynamicConstantNames:
130131
- ICONV_IMPL
@@ -518,6 +519,7 @@ services:
518519
scanDirectories: %scanDirectories%
519520
checkDependenciesOfProjectExtensionFiles: %resultCacheChecksProjectExtensionFilesDependencies%
520521
parametersNotInvalidatingCache: %parametersNotInvalidatingCache%
522+
skipResultCacheIfOlderThanDays: %resultCacheSkipIfOlderThanDays%
521523

522524
-
523525
class: PHPStan\Analyser\ResultCache\ResultCacheClearer

Diff for: conf/parametersSchema.neon

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ parametersSchema:
148148
earlyTerminatingMethodCalls: arrayOf(listOf(string()))
149149
earlyTerminatingFunctionCalls: listOf(string())
150150
resultCachePath: string()
151+
resultCacheSkipIfOlderThanDays: int()
151152
resultCacheChecksProjectExtensionFilesDependencies: bool()
152153
dynamicConstantNames: listOf(string())
153154
customRulesetUsed: schema(bool(), nullable())

Diff for: src/Analyser/ResultCache/ResultCacheManager.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public function __construct(
8686
private array $scanDirectories,
8787
private bool $checkDependenciesOfProjectExtensionFiles,
8888
private array $parametersNotInvalidatingCache,
89+
private int $skipResultCacheIfOlderThanDays,
8990
)
9091
{
9192
}
@@ -148,11 +149,12 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ?
148149
return new ResultCache($allAnalysedFiles, true, time(), $meta, [], [], [], [], [], [], [], []);
149150
}
150151

151-
if (time() - $data['lastFullAnalysisTime'] >= 60 * 60 * 24 * 7) {
152+
$daysOldForSkip = $this->skipResultCacheIfOlderThanDays;
153+
if (time() - $data['lastFullAnalysisTime'] >= 60 * 60 * 24 * $daysOldForSkip) {
152154
if ($output->isVeryVerbose()) {
153-
$output->writeLineFormatted('Result cache not used because it\'s more than 7 days since last full analysis.');
155+
$output->writeLineFormatted(sprintf("Result cache not used because it's more than %d days since last full analysis.", $daysOldForSkip));
154156
}
155-
// run full analysis if the result cache is older than 7 days
157+
// run full analysis if the result cache is older than X days
156158
return new ResultCache($allAnalysedFiles, true, time(), $meta, [], [], [], [], [], [], [], []);
157159
}
158160

0 commit comments

Comments
 (0)