Skip to content

[TwigBundle] Use kernel.build_dir to store the templates known at build time #54384

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

Open
wants to merge 1 commit into
base: 7.3
Choose a base branch
from

Conversation

Okhoshi
Copy link
Contributor

@Okhoshi Okhoshi commented Mar 23, 2024

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
Issues none
License MIT

Follow up to #50391, set up the Twig TemplateCacheWarmer to use the kernel.build_dir instead of kernel.cache_dir. A new argument is added to its constructor to specify the directory to use for the cache.

@Okhoshi Okhoshi requested a review from yceruto as a code owner March 23, 2024 21:49
@carsonbot carsonbot added this to the 7.1 milestone Mar 23, 2024
@Okhoshi Okhoshi force-pushed the twig-cache-build-dir branch 6 times, most recently from fb68b3c to 0bc3774 Compare March 24, 2024 14:59
@Okhoshi Okhoshi force-pushed the twig-cache-build-dir branch from 0bc3774 to c5b4ab0 Compare March 25, 2024 06:31
@Okhoshi Okhoshi force-pushed the twig-cache-build-dir branch from c5b4ab0 to 95b994c Compare March 25, 2024 08:04
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

Very good idea.

@Okhoshi Okhoshi force-pushed the twig-cache-build-dir branch 2 times, most recently from 0dbdd9b to 40e485c Compare March 27, 2024 10:41
@stof
Copy link
Member

stof commented Mar 27, 2024

shouldn't this dual cache setup be disabled when autoReload is enabled ? Otherwise, any template cached in the readonly cache won't be reloaded (as the cache never writes the new content) which will break the DX

@Okhoshi
Copy link
Contributor Author

Okhoshi commented Mar 27, 2024

shouldn't this dual cache setup be disabled when autoReload is enabled ? Otherwise, any template cached in the readonly cache won't be reloaded (as the cache never writes the new content) which will break the DX

I don't think it needs to. Looking at the Environment::loadTemplate method, it skips the cache::load call if autoReload is enabled, and calls cache::write directly. As the ChainCache propagates the write to all caches, from that moment, only the Runtime cache will be used, with the updated copy of the template.
Or did I miss something ?

@Okhoshi Okhoshi force-pushed the twig-cache-build-dir branch from 5155bf6 to 3483575 Compare December 7, 2024 12:13
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

We're close to the result we wanted. Do you want to continue @Okhoshi?

@Okhoshi Okhoshi force-pushed the twig-cache-build-dir branch 2 times, most recently from 5c7c0b8 to bf25c25 Compare April 1, 2025 07:29
@Okhoshi Okhoshi requested a review from GromNaN April 1, 2025 07:31
@Okhoshi Okhoshi force-pushed the twig-cache-build-dir branch from bf25c25 to 70757d5 Compare April 1, 2025 08:15
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

To summarize the configuration:

  • cache === false: No cache
  • cache is string path: Filesystem cache using the configured path, warmed by cache:warmup.
  • cache === true && auto_reload === true: (debug mode) Filesystem cache in the cache dir, warmed by cache:warmup
  • cache === true && auto_reload === false: (prod mode) Read-only filesystem cache in the build dir warmed by cache:warmup command, and filesystem cache in %kernel.cache_dir%/twig for dynamic templates.

It would be perfect to add service definition tests for each configuration, using micro-kernels in the tests.

@Okhoshi Okhoshi force-pushed the twig-cache-build-dir branch from 70757d5 to b55820e Compare April 1, 2025 15:41
@Okhoshi Okhoshi requested a review from GromNaN April 8, 2025 09:46
@Okhoshi Okhoshi force-pushed the twig-cache-build-dir branch from b55820e to 1a38f61 Compare April 8, 2025 11:36
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

I tested it on a project and got some functional feedback.

@GromNaN
Copy link
Member

GromNaN commented Apr 11, 2025

Tests are failing.

Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException: You have requested a non-existent parameter "kernel.build_dir". Did you mean this: "kernel.cache_dir"?

…uild time

Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>
@Okhoshi Okhoshi force-pushed the twig-cache-build-dir branch from a0bbca5 to 0f841d2 Compare April 11, 2025 15:04
@Okhoshi
Copy link
Contributor Author

Okhoshi commented Apr 11, 2025

Tests are failing.

Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException: You have requested a non-existent parameter "kernel.build_dir". Did you mean this: "kernel.cache_dir"?

Fixed, I didn't realise the tests were using a smaller kernel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" Status: Needs Review TwigBundle
Projects
None yet
Development

Successfully merging this pull request may close these issues.