frankenphp icon indicating copy to clipboard operation
frankenphp copied to clipboard

Cache (Twig) is not regenerated in dev mode

Open COil opened this issue 3 years ago • 6 comments

Hi, I use the FrankenPHP demo with the worker mode. If we modify a Twig template (with the dev env), docker has to be restarted, so the changes are taken in account. Is it a limitation of the worker mode?

And even if we clear the cache manually, we still have to restart FrankenPHP so see the new changes.

COil avatar Oct 22 '22 08:10 COil

Yes it's intended. Once the file is loaded in memory by PHP (in this case the PHP file corresponding to the Twig template), it will never be parsed and executed again: it stays in memory.

A solution to use the worker mode in dev would be to add a watcher option that will restart the worker if one of the watched files change. To do so, we could use fsnotify: https://github.com/fsnotify/fsnotify

dunglas avatar Oct 22 '22 08:10 dunglas

As a workaround @COil, you could try doing something like this in dev mode: https://github.com/dunglas/frankenphp/issues/37#issue-1413245382

withinboredom avatar Oct 22 '22 09:10 withinboredom

The problem is that even FrankenPHP is restarted, the Symfony cache still has to be regenerated. That's what I tried to fix with https://github.com/strangebuzz/cache-watcher. I have to modify it to use https://github.com/fsnotify/fsnotify BTW. Ideally, both should be done.

COil avatar Oct 23 '22 06:10 COil

IIRC, Twig allows you to disable caches too? I can't remember if Symphony exposes this option easily, as it is quite a bit lower level and usually not desired, but that may possibly be a simpler solution in this case.

withinboredom avatar Oct 23 '22 08:10 withinboredom

I took Twig as an example, but it must be the same with the different cache types. Env vars, yaml, translation, entities... Check out https://github.com/strangebuzz/cache-watcher/blob/b5b16d039f7cc59e79ccbad949f2c72a4465e92c/symfony/files.go#L49 (Symfony)

COil avatar Oct 23 '22 09:10 COil

👍, I think what @dunglas suggested would be the simplest long-term solution; I was just trying to help you discover a workaround without a bunch of code churn.

withinboredom avatar Oct 23 '22 11:10 withinboredom

Closing this for now as it's an expected behaviour.

COil avatar Oct 27 '22 13:10 COil