Invalidate the cache when a local checker's code changes by gnutix · Pull Request #211 · ecsphp/ecs-src · GitHub
Skip to content

Invalidate the cache when a local checker's code changes - #211

Open
gnutix wants to merge 1 commit into
ecsphp:mainfrom
gnutix:cache-local-checker-sources
Open

gnutix wants to merge 1 commit into
ecsphp:mainfrom
gnutix:cache-local-checker-sources

Conversation

@gnutix

@gnutix gnutix commented Oct 20, 2026

Copy link
Copy Markdown

Problem

The cache's configuration hash covers the registered checkers' class names, their configuration and the ECS version, but not their code. A project that ships its own fixer or sniff (registered from src/, tools/, …) keeps getting cached "no errors" for every unchanged file after editing that checker, until someone thinks of --clear-cache. CI caches restored from a previous run have the same problem, and nothing tells you the results are stale.

Fix

FileHashComputer::computeConfig() now also hashes the source files of registered checkers that live outside vendor/, together with their parent classes and traits. Checkers under vendor/, which covers every built-in rule in an installed ECS, are skipped: they only change with their package. In practice that means reading only the handful of custom checker files a project has, once per run.

Only file contents are hashed, not their paths, so the same project checked out elsewhere (a git worktree, a CI runner) keeps its cache.

testInvalidateCacheOnLocalCheckerChange registers a local sniff, edits its file and expects a different configuration hash; it fails without the change.

Context

PHP-CS-Fixer considered hashing every fixer's code in PHP-CS-Fixer/PHP-CS-Fixer#7003, which stalled partly on the cost of reading hundreds of vendor fixer files per run; skipping vendor/ avoids that cost. Until now we worked around it by feeding a hash of our fixers into withCache(namespace: …), which only works because the namespace happens to be part of the hashed parameters.

🤖 Generated with Claude Code

https://claude.ai/code/session_0187H51XtF5pkbEiJDmttSnZ

The configuration hash covered the registered checkers' class names and
configuration, so editing a project's own fixer or sniff kept serving
results cached with its previous code until --clear-cache. Hash the source
files of checkers living outside vendor/ (with their parents and traits)
into it; vendor checkers still change only with their package.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0187H51XtF5pkbEiJDmttSnZ

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first glance, this seems quite costly to help with cache.
I'd accept some non-reflection approach, like package version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants