Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Pawel Mikolajczuk:
Custom Caching for Twig
Aug 16, 2017 @ 11:07:07

In this post to his Medium blog Pawel Mikolajczuk shares some helpful tips for getting the most performance out of your Twig output with some custom caching techniques.

In Superdesk Publisher we have implemented Mutlitenancy with possibility to have multiple themes (but one activated). To make process of switching, uploading and updating themes for tenant we had to came up with solution to clear cache only for one particular theme not the whole instance (with many organisations and tenants).

To achieve that we created custom Twig Cache class.

He then shares the code for the class, extending the base Twig filesystem caching, to work with the multi-tenant architecture. It ensures that the output from one account is completely separate from another, preventing concerns of the wrong data being shown to the wrong user. He also shows how to enable it in the application configuration (Symfony) and a custom "compiler pass" class to finish the integration.

tagged: twig custom cache class output multitenant architecture

Link: https://medium.com/@pawel.mikolajczuk/custom-caching-for-twig-f9a7303cebdd