This article applies to Drupal 8 and later websites.
In Drupal 8+, what if my theme does not render as expected?
Twig is used for Drupal 8+ theming, and it relies on having its own cache of compiled Twig templates, which is separate from other caches that are cleared with the
drush cache:rebuild command in Drupal 8+. Drupal 8+ websites on Acquia Cloud Enterprise can run into issues where cached Twig templates fall out of sync on different web server instances when changes to themes are being made and a code deployment has been performed. When you make changes to themes in Drupal 8+ websites on Acquia Cloud Enterprise, connect to each web server instance and run a command like this, to remove the outdated Twig templates:
drush @[sitename].[prod] --uri=http://[site_URL]/ ev '\Drupal\Core\PhpStorage\PhpStorageFactory::get("twig")->deleteAll();'
This workaround can temporarily be automated through a mix of Cloud Hooks and Cloud API's https://cloudapi.acquia.com/#GET__sites__site_envs__env_servers__server-instance_route.
The problem arises from having separate copies of the compiled Twig templates on each web server instance and (the related Drupal core issue https://www.drupal.org/node/2752961 and https://www.drupal.org/project/drupal/issues/2979669).
Acquia Cloud has a script that will clear twig caches when code is deployed to Acquia Cloud, but this may not resolve this problem in all cases.
If your volume is filling due to twig cache files:
- Consider adding a scheduled (cron) task to automate the clearing of twig template files on a regular interval. Use the above drush command as a starting point.
- Spend some time with twig debugging tools to better understand why your theme files are generating large numbers of twig cache files.