Skip to content

Reuse cache entries for identical file contents#236

Merged
llaville merged 1 commit into
overtrue:mainfrom
StantonMatt:codex/reuse-cache-by-content
Jun 3, 2026
Merged

Reuse cache entries for identical file contents#236
llaville merged 1 commit into
overtrue:mainfrom
StantonMatt:codex/reuse-cache-by-content

Conversation

@StantonMatt

Copy link
Copy Markdown
Contributor

Fixes #224.

This changes readable file cache keys to use the file fingerprint instead of the path-derived key, so identical files copied into separate release directories can share the same cache entry. The existing sanitized path key remains as the fallback for unreadable or unknown paths.

Tests:

  • docker run --rm -v "$PWD:/app" -w /app composer:2 vendor/bin/phpunit --no-progress --testdox --do-not-cache-result --testsuite cache
  • docker run --rm -v "$PWD:/app" -w /app composer:2 vendor/bin/phpunit --no-progress --testdox --do-not-cache-result
  • git diff --check

Signed-off-by: Matthew Stanton <stantonmatthewj@gmail.com>
@llaville llaville self-assigned this Jun 3, 2026
@llaville

llaville commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Confirmed by running your code in real conditions too !

First Run

bin/phplint lint tests/Cache/Fixtures/releases/ --extensions fixture -vv
  RUN  '/usr/local/bin/php' '-d error_reporting=E_ALL' '-d display_errors=On' '-d memory_limit=-1' '-l' '-n' '/shared/backups/forks/phplint-cache/tests/Cache/Fixtures/releases/3119/test.fixture'
  RUN  '/usr/local/bin/php' '-d error_reporting=E_ALL' '-d display_errors=On' '-d memory_limit=-1' '-l' '-n' '/shared/backups/forks/phplint-cache/tests/Cache/Fixtures/releases/3118/test.fixture'
  RES  Command ran successfully
  RES  Command ran successfully

phplint 9.7.x-dev@3e93b16 by overtrue and contributors.

Runtime       : PHP 8.2.31
Configuration : /shared/backups/forks/phplint-cache/.phplint.yml

┌──────────────────┬────────────────────────────────────┐
│ Name             │ Value                              │
├──────────────────┼────────────────────────────────────┤
│ path             │ ["tests/Cache/Fixtures/releases/"] │
├──────────────────┼────────────────────────────────────┤
│ configuration    │ ".phplint.yml"                     │
│ no-configuration │ false                              │
│ exclude          │ ["vendor"]                         │
│ extensions       │ ["fixture"]                        │
│ jobs             │ 10                                 │
│ no-cache         │ false                              │
│ cache            │ ".phplint.cache"                   │
│ cache-dir        │ ".phplint.cache"                   │
│ cache-ttl        │ 3600                               │
│ no-progress      │ false                              │
│ progress         │ "printer"                          │
│ output           │ null                               │
│ format           │ ["console"]                        │
│ warning          │ true                               │
│ memory-limit     │ -1                                 │
│ ignore-exit-code │ false                              │
│ bootstrap        │ ""                                 │
└──────────────────┴────────────────────────────────────┘


Time: 35 ms, Memory: 8.0 MiB, Cache: 0 hit, 2 misses, Processes: 2


 [OK] 2 files

Second Run

bin/phplint lint tests/Cache/Fixtures/releases/ --extensions fixture -vv

phplint 9.7.x-dev@3e93b16 by overtrue and contributors.

Runtime       : PHP 8.2.31
Configuration : /shared/backups/forks/phplint-cache/.phplint.yml

┌──────────────────┬────────────────────────────────────┐
│ Name             │ Value                              │
├──────────────────┼────────────────────────────────────┤
│ path             │ ["tests/Cache/Fixtures/releases/"] │
├──────────────────┼────────────────────────────────────┤
│ configuration    │ ".phplint.yml"                     │
│ no-configuration │ false                              │
│ exclude          │ ["vendor"]                         │
│ extensions       │ ["fixture"]                        │
│ jobs             │ 10                                 │
│ no-cache         │ false                              │
│ cache            │ ".phplint.cache"                   │
│ cache-dir        │ ".phplint.cache"                   │
│ cache-ttl        │ 3600                               │
│ no-progress      │ false                              │
│ progress         │ "printer"                          │
│ output           │ null                               │
│ format           │ ["console"]                        │
│ warning          │ true                               │
│ memory-limit     │ -1                                 │
│ ignore-exit-code │ false                              │
│ bootstrap        │ ""                                 │
└──────────────────┴────────────────────────────────────┘


Time: 5 ms, Memory: 8.0 MiB, Cache: 2 hits, 0 miss, Process: 0


 [OK] 2 files

Great Job @StantonMatt

@llaville llaville merged commit 573b4c6 into overtrue:main Jun 3, 2026
5 checks passed
llaville pushed a commit that referenced this pull request Jun 3, 2026
Signed-off-by: Matthew Stanton <stantonmatthewj@gmail.com>
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.

Linting the very same file in different file-system locations should re-use a single cache file

2 participants