---
title: "Drupal 8-9: Twig cache"
date: "2023-08-24T17:07:51+00:00"
summary:
image:
type: "article"
url: "/acquia-cloud-platform/help/93181-drupal-8-9-twig-cache"
id: "4941b5d7-6c82-4a87-8903-d13fc7e67f44"
---

Table of contents will be added

Issue
-----

In Drupal 8-9, what if my theme does not render as expected?

Resolution
----------

### Twig Cache

Twig is used for Drupal 8-9 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-9. Drupal 8-9 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-9 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 via a mix of Cloud Hooks and Cloud API's [https://cloudapi.acquia.com/#GET\_\_sites\_\_site\_envs\_\_env\_servers\_\_server-instance\_route](/node/55865)

Cause
-----

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](https://www.drupal.org/node/2752961)).

More information can be found in our product documentation on [Known issues in Acquia Cloud](/node/55869)[.](https://docs.acquia.com/acquia-cloud/known-iues/)

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](/node/94251) to better understand why your theme files are generating large numbers of twig cache files.