Repository navigation
Description
Description
The CI cache documentation still recommends forcing FileCacheStorage. However, with Rector 2.6.2, CacheFactory selects MemoryCacheStorage whenever CI is detected:
if ((new CiDetector())->isCiDetected()) {
return new Cache(new MemoryCacheStorage());
}This happens before the configured cache directory/storage can be used. As a result, a persisted GitHub Actions cache is restored successfully, but Rector does not read the cached entries in the next run.
Reproduction
Configuration:
<?php
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withCache(
cacheClass: FileCacheStorage::class,
cacheDirectory: __DIR__.'/.rector.cache',
);GitHub Actions cache:
- name: Rector Cache
uses: actions/cache@v4
with:
path: .rector.cache
key: ${{ runner.os }}-rector-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-rector-
- run: mkdir -p .rector.cache
- run: vendor/bin/rector process --dry-runThe cache action reports a successful restore, but the following Rector run behaves like a cold run and reparses the entire codebase.
Expected behavior
When FileCacheStorage is explicitly configured, Rector should use it in CI so that cache entries restored from a previous job or workflow run are reused.
Actual behavior
Rector uses MemoryCacheStorage in CI. The cache directory may be restored and populated, but the restored entries are ignored because the in-memory cache starts empty for each process.
This increases CI runtime significantly. In our Laravel application, Rector takes approximately 77 seconds in CI despite restoring the cache successfully. Locally, the same configuration drops from roughly 33 seconds on a cold run to 7.5 seconds on a warm run.
Possible fixes
One of the following would resolve the issue:
- Preserve the documented cacheClass: FileCacheStorage override and give it precedence over the CI default.
- Add an explicit supported configuration option or environment variable to enable file caching in CI.
- Update the documentation to explain that external CI caches are no longer supported and remove the GitHub Actions caching guidance.
PR rectorphp/rector-src#8311 states that an explicit cacheClass() configuration should still win, but the current CacheFactory behavior appears to select the in-memory cache before honoring that configuration in a CI.
Related PR: rectorphp/rector-src#8311
Current documentation: https://getrector.com/documentation/cache-in-ci
The strongest point is the contradiction between PR's stated compatibility promise and the current (changed) CacheFactory behavior when having an explicit configuration.
Activity
localheinz commentedon Aug 17, 2026
Working around this until the fix lands in a release by unsetting the
GITHUB_ACTIONSvariable:TomasVotruba commentedon Aug 17, 2026
@joostdebruijn Thanks for clear report. Can you verify latest dev handles it as expected?
joostdebruijn commentedon Aug 17, 2026
@TomasVotruba I've tested against package version
8eed4698083bdd1960877fb3e7ff8b76e73ef600and it works as expected. Thanks!TomasVotruba commentedon Aug 17, 2026
Great, I'll make release this week. Stay tuned
TomasVotruba commentedon Aug 20, 2026
Thanks, closing as fixed and released 👍