netgen-layouts / layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.
https://netgen.io/layouts
MIT License
36 stars 6 forks source link

[Bug] \Netgen\Bundle\LayoutsBundle\EventListener\TwigExtensionsListener invalidates all Twig cache #24

Closed dkarlovi closed 2 years ago

dkarlovi commented 2 years ago

This listener will add a Twig extension at runtime. The extension is not part of the Twig options hash which is used to generate the template cache key. When Symfony's cache warmers are running, the options hash doesn't contain the extensions added here.

This means all the Twig cache generated by the cache warmer is invalid and new cache must be created at runtime, making this bundle incompatible with read-only Symfony deployments like Docker and Lambda.

emodric commented 2 years ago

Good point. I can add the required Twig extension (only one currently) to the list of services and remove this listener altogether.

The reason why this was done like this was, that previously, we had another extension (Intl IIRC) which we used, but we could not make sure that it is activated only if it wasn't already activated. In retrospective, same might've been achieved by a compiler pass.

Currently, the only extension left has a very low chance of existing outside of Layouts (since it's one of our custom ones), so I'll just go ahead and add it directly as a service.

emodric commented 2 years ago

@dkarlovi Fixed in 1.3.6

dkarlovi commented 2 years ago

@emodric nice! :beers: