Skip to content

Deprecate cacheClass(), select cache storage internally - #8311

Draft
TomasVotruba wants to merge 3 commits into
mainfrom
claude/deprecate-cache-class-4bavrw
Draft

Deprecate cacheClass(), select cache storage internally#8311
TomasVotruba wants to merge 3 commits into
mainfrom
claude/deprecate-cache-class-4bavrw

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Aug 6, 2026

Copy link
Copy Markdown
Member

What

Moves the file-vs-memory cache storage decision out of user config and into CacheFactory, and deprecates the public cacheClass() API.

Why

cacheClass() exposed the CacheStorageInterface implementation as a public config knob, but there are only two implementations and only one is ever useful to end users:

  • FileCacheStorage — the real, cross-run cache.
  • MemoryCacheStorage — an in-process array, wiped when the PHP process exits.

A Rector CLI run processes every file once in a single process (hasFileChanged() loads before cacheFile() saves), so memory storage delivers zero cross-invocation benefit — the whole value of the cache is between runs. So cacheClass() was an implementation detail leaked as public API with no valid production use.

How

  • CacheFactory now resolves the storage internally: an explicit cacheClass() still wins, otherwise file cache locally and in-memory cache in CI (where the ephemeral workspace makes writing a cache that is never re-read wasted IO). This is the exact policy that previously lived in config/config.php, just moved behind the factory — behaviour-preserving.
  • RectorConfig::cacheClass() and the withCache(cacheClass:) argument are marked #[Deprecated]. They remain functional for the rare case that needs to force a specific storage — e.g. the e2e cache tests, which force FileCacheStorage so they can verify the persisted cache across two runs even on CI.
  • Internal callers set the parameter directly instead of calling the deprecated method, so PHPStan's deprecation rules stay green.

No new environment variables or config surface. Split out from a combined branch; the FileCacheStorage::save() simplification is #8312.

Move the file-vs-memory cache storage decision into CacheFactory: an explicit
cacheClass() still wins, otherwise file cache is used locally and in-memory
cache in CI, where the ephemeral workspace makes writing a cache that is never
re-read wasted IO. Previously this CI branch lived in config/config.php.

Mark RectorConfig::cacheClass() and the withCache(cacheClass:) argument as
deprecated; they stay functional for the rare case that needs to force a
specific storage (e.g. the e2e cache tests).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ti6vHRo3xLSHw84rxUw6Lb
@TomasVotruba
TomasVotruba force-pushed the claude/deprecate-cache-class-4bavrw branch from 1afd62f to 47ddf72 Compare August 6, 2026 15:31
@TomasVotruba
TomasVotruba force-pushed the claude/deprecate-cache-class-4bavrw branch from 8355c2c to b9b3b51 Compare August 6, 2026 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants