Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caching and multiple configurations for a project #3755

Closed
mfn opened this issue Aug 20, 2020 · 12 comments
Closed

Caching and multiple configurations for a project #3755

mfn opened this issue Aug 20, 2020 · 12 comments

Comments

@mfn
Copy link

mfn commented Aug 20, 2020

Feature request

The documentation https://phpstan.org/user-guide/result-cache is quite clear to me:

You should always analyse the whole project - the list of paths passed to the analyse command should be the same to take advantage of the result cache. If the list of paths differs from run to run, the cache is rebuilt from the ground up each time.

I experiences this when having a project with two phpstan configuration files:

  • phpstan.neon
    and
  • phpstan-tests.neon

Running phpstan with one config invalidates the result of the other.

The solution was to be explicit about the tmpDir in each configuration file, as documented in https://phpstan.org/config-reference#caching .

Suggestion: would it make sense to consider the "config file name" as part of the cache key so multiple configs wouldn't cancel out each other?

Thanks! :)

@ondrejmirtes
Copy link
Member

Hi, there's simply one result cache per tmpDir. Your needs are already solved with different tmpDir per config file so this change would seem redundant.

You can also probably solve this by merging phpstan.neon and phpstan-tests.neon and run PHPStan only once. If you execute different rules (different level) for src and tests then you can probably solve this by introducing the baseline :)

@mfn
Copy link
Author

mfn commented Aug 20, 2020

If you execute different rules (different level) for src and tests then you can probably solve this by introducing the baseline :)

No, they're completely different. Different parameters, different rules, etc.

there's simply one result cache per tmpDir.

Oh. But how does this work when I've multiple, completely independently, projects who all default to the system tmpDir? Are they interfering with each other, too?

@ondrejmirtes
Copy link
Member

Are they interfering with each other, too?

Currently yes.

@mfn
Copy link
Author

mfn commented Aug 20, 2020

Uh… 💥 😏

@voku
Copy link
Contributor

voku commented Nov 13, 2020

Thanks for this discussion, now I know that I have to configure different tmp directories, but it would be even clearer if there where a cacheDir setting.

@mfn
Copy link
Author

mfn commented Nov 14, 2020

With the recent support of PhpStorm for phpstan, I think I observed the following:

  • run phpstan regular (in the terminal), builds cache
  • run it regular again, uses cache
  • configure phpstan in phpstorm
  • when phpstorm triggers the validation (of a single file!) it seems the whole cache is invalidated
  • and when I run phpstan regular (terminal) again, it rebuilds the cache

In both cases I use the same configuration.

Anyone observing this too?

Is this an independent issue or maybe related to this?

@ondrejmirtes
Copy link
Member

This is currently expected - running PHPStan on a single file overwrites the whole cache and caches the result for that file.

@mfn
Copy link
Author

mfn commented Nov 14, 2020

I guess I could fix it by providing yet another configuration file for the PhpStorm integration with yet another tmpDir… 🤔

@ondrejmirtes
Copy link
Member

I could skip cache-saving in PHPStan when only files are passed on the command line.

@ondrejmirtes
Copy link
Member

I just made a few improvements to result cache:

  • Result cache does not get restored and saved when only files and not directories are passed as analysed paths: phpstan/phpstan-src@dd11e25 (released in 0.12.57)
  • Result cache does not get invalidated when only ignoreErrors changes (phpstan/phpstan-src@ef84d94) - this makes working with the baseline instantaneous! (released in 0.12.57)
  • Configurable result cache path (phpstan/phpstan-src@518b20d) - now in dev-master

So this issue can be closed, because now you can set resultCachePath: %tmpDir%/resultCache-tests.php in phpstan-tests.neon and it will do what you expect ;)

@mfn
Copy link
Author

mfn commented Nov 21, 2020

Nice, thank you @ondrejmirtes !

@github-actions
Copy link

github-actions bot commented May 7, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants