Skip to content

Note that resultcaches might be overwritten if tmpDir is not unique - #7260

Closed
spaze wants to merge 1 commit into
phpstan:1.7.xfrom
spaze:spaze/unique-tmpdir-docs
Closed

spaze wants to merge 1 commit into
phpstan:1.7.xfrom
spaze:spaze/unique-tmpdir-docs

Conversation

@spaze

@spaze spaze commented May 18, 2022

Copy link
Copy Markdown
Contributor

So, uhh, this took me a really long time. Since the day the result cache has been introduced, I've had a feeling that something is not right but it was always just a feeling. Until today. (Spoiler alert: my config wasn't perfect)

I'm running PHPStan on different projects (sometimes even multiple PHPStan configs in one project) and finally I've realized that the result cache from one project was being overwritten by a result cache from some other project (or config file).

I've read the related documentation several times but only today it eventually occurred to me. This might help other people like me (I know you're there, hello?).

@herndlm

herndlm commented May 19, 2022 •

Copy link
Copy Markdown
Contributor

I basically had the same experience, see #4237 (comment) where setting cacheFilePath was suggested. Not sure if the whole tmpDir should be changed hmm

If this would "work" out of the box it would be perfect, otherwise a change like this is great, yeah :)

@spaze

spaze commented May 19, 2022

Copy link
Copy Markdown
Contributor Author

I've seen resultCachePath but because it's not documented I've opted for changing the whole tmpDir. I can add resultCachePath here, too, but I wasn't sure whether tempResultCachePath would also need to be changed, probably not.

But of course, out of the box would be perfect :-)

@ondrejmirtes

Copy link
Copy Markdown
Member

I'd rather improve the situation than document the bad behaviour :)

What about this:

  1. Do not change anything if the project explicitly sets tmpDir. It usually means that the CI depends on %tmpDir%/resultCache.php to exist because they persist it across runs.
  2. Otherwise (if the tmpDir is the default system one which means it's gonna be shared across all projects), append something like current working directory hash to %resultCachePath%. So it's not going to be /tmp/phpstan/resultCache.php, but something like /tmp/phpstan/resultCache-xyz.php where xyz is derived from CWD.

WDYT?

@spaze

spaze commented May 21, 2022

Copy link
Copy Markdown
Contributor Author

That sounds even better! In my case, it should be a hash of a config file path, not just dir path. I'm using two .neon files in the same dir, they're each for a different part of the codebase, so they would share the same dir and the cache would be overwritten anyway.

Do you think a hash of a config file is doable?

@ondrejmirtes

Copy link
Copy Markdown
Member

I'll try to think of all the variables that are relevant for this and we'll see :)

@spaze

spaze commented May 21, 2022

Copy link
Copy Markdown
Contributor Author

Cool, thanks! I can then update this PR to document the new behavior unless of course you'll do it :-)

@ondrejmirtes

Copy link
Copy Markdown
Member

Opened an issue to make sure it's not lost: #7379

This pull request was closed.
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.

3 participants