Skip to content

TemplateCacheWarmer ignores twig.cache configuration #28009

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
nesl247 opened this issue Jul 19, 2018 · 1 comment
Closed

TemplateCacheWarmer ignores twig.cache configuration #28009

nesl247 opened this issue Jul 19, 2018 · 1 comment

Comments

@nesl247
Copy link

nesl247 commented Jul 19, 2018

Symfony version(s) affected: 4.1.1

Description
Symfony's twig-bundle is ignoring the twig.cache configuration, and still attempting to warm the cache.

How to reproduce
Change twig.cache to false and run cache:clear with symfony/twig-bundle installed.

Possible Solution

Additional context
The reason this is problematic is in my case, we are loading templates from a DB. We do not want these templates to be fetched ahead of time, as there are a ton of them (potentially thousands).

This is related to symfony/symfony-docs#10101 in which the documentation incorrectly specifies how to disable caching.

@nesl247
Copy link
Author

nesl247 commented Jul 20, 2018

I've since discovered this only occurs when you have a custom loader in your application. The second you have a class that implements Twig\Loader\LoaderInterface, the issue occurs.

I tested a fresh symfony 4 application and required twig-bundle. Before clearing the cache, the twig directory was there. After adding cache: false to twig.yaml, clearing the cache (rm -rf var/cache/dev) and then rerunning composer run post-update-cmd, the twig directory is no longer there.

However, as soon as I created my TestLoader, the exists() method was being called during this process. I know since I added an exception to it, as it shouldn't have been called.

https://github.com/nesl247/symfony-twig-cache-warmer-test is the reproduction of this issue. If you remove src/TestLoader.php, the issue goes away.

Edit: I was able to fix my issue without disabling cache by changing the priority on the custom loader to -1. However, this bug still stands because if cache is false, then the loader should never have been called to begin with.

@fabpot fabpot closed this as completed Sep 4, 2018
fabpot added a commit that referenced this issue Sep 4, 2018
…led (xabbuh)

This PR was merged into the 2.8 branch.

Discussion
----------

[TwigBundle] remove cache warmers when Twig cache is disabled

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #28009
| License       | MIT
| Doc PR        |

Commits
-------

ef1f7ff remove cache warmers when Twig cache is disabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants