Skip to content

[FrameworkBundle] Add --watch option to cache:clear command #32764

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

Closed
wants to merge 1 commit into from

Conversation

maidmaid
Copy link
Contributor

@maidmaid maidmaid commented Jul 26, 2019

Q A
Branch? 4.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets /
License MIT
Doc PR /

Inspired by the watch of webpack, this PR allows to clear the cache immediately after touching the code base of the project. Indeed, from the DX perspective, the cache regeneration is always painful because it is started after an user action such as running a command or making a request through the browser, and we undergo the time of recompilation that should ideally be realised before.

Peek 2019-07-26 15-16

@javiereguiluz
Copy link
Member

@maidmaid just asking: does it take so much time to clear the cache in your real apps? Maybe they are so big and/or complex that they do. But I'm curious because I usually don't deal with the cache at all and I have no issue. And when I need to clear the cache for some reason, I always run rm -fr var/cache/*

@maidmaid
Copy link
Contributor Author

Yes it does : something like 10'' for a complete cache:clear, and more when I'm working from a vagrant/container.

Copy link

@pifaace pifaace left a comment

Choose a reason for hiding this comment

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

Hi @maidmaid !
I tested your feature in an example project, it seems to be fine for me.
I just notice one thing :
If I'm running cache:clear --watch and then I install a new package like

composer require orm

the autoloader failed and the watch cancelled
https://zupimages.net/up/19/31/p5yj.png

Idk if thats normal

@nicolas-grekas
Copy link
Member

Do we need some locking mechanism?
When the command is recomputing in the background and a web request is made, this should maybe block?

@nicolas-grekas
Copy link
Member

Locking implemented in #33701

@nicolas-grekas
Copy link
Member

What about relying on #31462 here? Could you please have a look?

fabpot added a commit that referenced this pull request Oct 2, 2019
…pportunistic lock (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpKernel] wrap compilation of the container in an opportunistic lock

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

#32764 (comment)

This PR adds a lock around the compilation of the container. When two or more concurrent requests want to compile the container, the first one runs the computation and the others wait for its completion. If for any reasons the lock doesn't work, compilation happens as usual.

The effect is visible when developing locally:

Here is what all concurrent requests consume now:
![image](https://user-images.githubusercontent.com/243674/65603626-4e231d00-dfa6-11e9-8b6c-62dbd5eb30fe.png)

And here is what they will consume with this PR (they wait but reuse the just compiled container):
![image](https://user-images.githubusercontent.com/243674/65603733-7f9be880-dfa6-11e9-930b-ce793c3e280c.png)

Commits
-------

0b5b3ed [HttpKernel] wrap compilation of the container in an opportunistic lock
symfony-splitter pushed a commit to symfony/http-kernel that referenced this pull request Oct 2, 2019
…pportunistic lock (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpKernel] wrap compilation of the container in an opportunistic lock

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

symfony/symfony#32764 (comment)

This PR adds a lock around the compilation of the container. When two or more concurrent requests want to compile the container, the first one runs the computation and the others wait for its completion. If for any reasons the lock doesn't work, compilation happens as usual.

The effect is visible when developing locally:

Here is what all concurrent requests consume now:
![image](https://user-images.githubusercontent.com/243674/65603626-4e231d00-dfa6-11e9-8b6c-62dbd5eb30fe.png)

And here is what they will consume with this PR (they wait but reuse the just compiled container):
![image](https://user-images.githubusercontent.com/243674/65603733-7f9be880-dfa6-11e9-930b-ce793c3e280c.png)

Commits
-------

0b5b3ed [HttpKernel] wrap compilation of the container in an opportunistic lock
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
@nicolas-grekas nicolas-grekas modified the milestones: 4.4, next Nov 5, 2019
@nicolas-grekas
Copy link
Member

nicolas-grekas commented Feb 7, 2020

I'm closing because this can be achieved using a composer script, adding e.g. this under the "scripts" section of your composer.json:

"auto-cache-clear": [
    "while inotifywait -qqre modify -e delete -e create src/ config/; do bin/console cache:clear; done"
]

Then running composer auto-cache-clear.

The logic is also too basic: any changes in the app's directories will trigger a cache:clear. This will spam the command to me. It will increase the maintenance effort for sure, as ppl will ask for more fine-grained logic. Better not, especially when this can be achieved already with one line of bash.

Thanks for proposing.

@nicolas-grekas nicolas-grekas modified the milestones: next, 5.1 May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants