Answers.Body: <p>Investigating this one too. The 'Clean-up Temporary Data and Files' <a href="https://github.com/civicrm/civicrm-core/blob/06540d39dc2cedcadb19be5c351ef831a9133534/api/v3/Job.php#L631" rel="nofollow noreferrer">doesn't</a> clean the tplCache by default (oddly). You can make it do so by adding it to the command parameters:</p>
  <p><a href="https://i.sstatic.net/klkk7.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/klkk7.png" alt="enter image description here" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-29T09:45:22.340Z
Answers.Text: Thank you. In the end I got round the problem by breaking large mailings up into batches of 1000 using the CiviMail settings, but the tplCache=1 is a much neater solution. See also https://civicrm.stackexchange.com/questions/41876/civicrm-template-compiledir-template-c-folder-becomes-too-large-how-to-empty
Answers.UserDisplayName: Jern
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-17T12:07:39.123Z
Answers.LastActivityDate: 2024-02-17T12:07:39.123Z
Answers.UserDisplayName: Andrew West
Answers.Body: <p>Cache files are cleared by a scheduled job, which isn't enabled by default.  </p>
  
  <ul>
  <li>Go to <strong>Administer menu » System Settings » Scheduled Jobs</strong>.</li>
  <li>Find the row labeled <em>Clean-up Temporary Data and Files</em>.</li>
  <li>On that row, click <strong>more menu » Enable</strong>.</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-16T18:41:23.170Z
Answers.Text: I have this enabled but still have to manually clear the templates_c file almost daily. Not for the reasons stated about but just in general, parts of the CRM or website won't load until I do. Are there any other considerations along with this to add?
Answers.UserDisplayName: Christia
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-16T19:41:41.163Z
Answers.Text: @christia that sounds like you have a file ownership (and/or permissions) issue.  If this is happening almost daily, and I assume you're not logging into the server daily - that suggests that the Unix user running cron isn't the same as the Unix user running your webserver.
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-04T19:14:30.533Z
Answers.LastActivityDate: 2018-01-04T19:14:30.533Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.Body: <p>For the workaround, you can try to go to <code>/civicrm?directoryCleanup=1</code>.</p>
  <blockquote>
  <p><code>&amp;directoryCleanup=1</code> empties template cache in <code>civicrm/templates_c</code>.</p>
  </blockquote>
  <p>Read more: <a href="https://docs.civicrm.org/dev/en/latest/tools/debugging/#using-url-parameters" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/tools/debugging/#using-url-parameters</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-20T22:58:24.657Z
Answers.LastActivityDate: 2023-11-20T22:58:24.657Z
Answers.UserDisplayName: kenorb
Answers.Body: <p>Try changing the templates_c folder permissions to 777 recursively so that every sub directory would have 777 permission also.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-04T19:10:33.430Z
Answers.Text: Setting permissions to 777 is almost never a good idea, and hides the underlying permission issue.  Additionally, this does nothing to prevent CiviCRM from creating new template_c files with the default permissions.
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-04T16:51:32.277Z
Answers.LastActivityDate: 2018-01-04T16:51:32.277Z
Answers.UserDisplayName: Hassan Farooq
Body: <p>This is a problem I've had for three or four years, but never solved. I send a monthly mailing to about 50k contacts using CiviMail. Each mailing is scheduled using the standard CiviCRM job scheduling. All works fine except that during the sending, the templates_c/en_GB folder grows to about 30GB or more, and has to be emptied manually (either from the command line or using the the CiviCRM Clean Up Caches page) to stop the server from running out of disk space. The files and directories which are being created under templates_c/en_GB/ all seem to have plausible permissions (read and write for the Apache user, read only for everyone else), so I don't understand why they're not being cleared.</p>
  
  <p>Can anyone suggest anywhere to start looking for a solution? Thanks.</p>
  
  <p>This happens with the following set-up, but I have had the problem for a long time, with all previous versions as well.  </p>
  
  <p>CiviCRM 4.7.19<br>
  Joomla 3.7.2<br>
  php 7.0.19<br>
  MySQL 5.6.36  </p>
  
Tags: <civimail><permissions><cache><deleted>
Title: templates_c cache files not being deleted
ThreadText: # templates_c cache files not being deleted
  
  (Asked by: username_0 on 2017-06-06)
  
  This is a problem I've had for three or four years, but never solved. I send a monthly mailing to about 50k contacts using CiviMail. Each mailing is scheduled using the standard CiviCRM job scheduling. All works fine except that during the sending, the templates\_c/en\_GB folder grows to about 30GB or more, and has to be emptied manually (either from the command line or using the the CiviCRM Clean Up Caches page) to stop the server from running out of disk space. The files and directories which are being created under templates\_c/en\_GB/ all seem to have plausible permissions (read and write for the Apache user, read only for everyone else), so I don't understand why they're not being cleared.
  
  Can anyone suggest anywhere to start looking for a solution? Thanks.
  
  This happens with the following set-up, but I have had the problem for a long time, with all previous versions as well.
  
  CiviCRM 4.7.19  
  Joomla 3.7.2  
  php 7.0.19  
  MySQL 5.6.36
  
  **Tags:** civimail, permissions, cache, deleted
  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_1 on 2024-02-17. Score: 2 | Accepted answer
  
  Investigating this one too. The 'Clean-up Temporary Data and Files' [doesn't](https://github.com/civicrm/civicrm-core/blob/06540d39dc2cedcadb19be5c351ef831a9133534/api/v3/Job.php#L631) clean the tplCache by default (oddly). You can make it do so by adding it to the command parameters:
  
  [![enter image description here](https://i.sstatic.net/klkk7.png)](https://i.sstatic.net/klkk7.png)
  
  > **Comments:**
  > **username_0**: Thank you. In the end I got round the problem by breaking large mailings up into batches of 1000 using the CiviMail settings, but the tplCache=1 is a much neater solution. See also https://civicrm.stackexchange.com/questions/41876/civicrm-template-compiledir-template-c-folder-becomes-too-large-how-to-empty  
  
  ---
  
  ### Answer by username_2 on 2018-01-04. Score: 4
  
  Cache files are cleared by a scheduled job, which isn't enabled by default.
  
  * Go to **Administer menu » System Settings » Scheduled Jobs**.
  * Find the row labeled *Clean-up Temporary Data and Files*.
  * On that row, click **more menu » Enable**.
  
  > **Comments:**
  > **username_3**: I have this enabled but still have to manually clear the templates_c file almost daily. Not for the reasons stated about but just in general, parts of the CRM or website won't load until I do. Are there any other considerations along with this to add?  
  > **username_2**: @username_3 that sounds like you have a file ownership (and/or permissions) issue.  If this is happening almost daily, and I assume you're not logging into the server daily - that suggests that the Unix user running cron isn't the same as the Unix user running your webserver.  
  
  ---
  
  ### Answer by username_4 on 2023-11-20. Score: 0
  
  For the workaround, you can try to go to `/civicrm?directoryCleanup=1`.
  
  > `&directoryCleanup=1` empties template cache in `civicrm/templates_c`.
  
  Read more: <https://docs.civicrm.org/dev/en/latest/tools/debugging/#using-url-parameters>.
  
  
  ---
  
  ### Answer by username_5 on 2018-01-04. Score: -3
  
  Try changing the templates\_c folder permissions to 777 recursively so that every sub directory would have 777 permission also.
  
  > **Comments:**
  > **username_2**: Setting permissions to 777 is almost never a good idea, and hides the underlying permission issue.  Additionally, this does nothing to prevent CiviCRM from creating new template_c files with the default permissions.  
  
  ---
  
  