10

When doing developpment, i sometimes found it difficult to clear all the cache in a way i'm sure everything i have done is taken into account.

Let's take some examples :

  • in an extension, i do an override of some core .tpl file (i know i shouldn't do that but sometimes difficult to avoid) - will it work out of the box or do i need to clear some cache ?
  • in an extension, i create a new page or form with a custom menu xml file - what do i need to clean ?

What are the different level of caches involved ?

Is there a way to clean all caches in one shot like the drupal Flush all caches / drush cc all ?

14

For the first example, you need to 1. clear the compiled Smarty templates cache. In the second case you need to 2. rebuild the menu system using your xml file. 3. There are some db cache tables you sometimes need to clear out using mysql or a link in the UI. 4. Caching in the CMS can also affect CiviCRM pages.

  1. a) One way to do this is to go to Admin > System Settings > Cleanup Caches and Update Paths (civicrm/admin/setting/updateConfigBackend?reset=1), then click Save.

b) A more convenient method during development is to be able to append arguments to the url you are debugging to have the cleanup done automatically. Go to Administer > System Settings > Debugging and Error Handling.

Click to Enable Debugging. At this point you can add a key-value pair to your URLs to clear the compiled Smarty file cache under templates_c, and also if you want the upload file directory: Directory Cleanup -Empties template cache and/or temporary upload file folders. To empty template cache (civicrm/templates_c folder), add &directoryCleanup=1 To remove temporary upload files (civicrm/upload folder), add &directoryCleanup=2 To cleanup both, add &directoryCleanup=3

You might also want reset the session, since that caches various values: Session Reset - Resets all values in your client session. To trigger, add &sessionReset=2

  1. a) Enter the appropriate one of the following urls to rebuild the menu system, which also clears various caches:

Drupal sites: http:///index.php?q=civicrm/menu/rebuild&reset=1

Joomla 1.5 sites: http:///administrator/index2.php?option=com_civicrm&task=civicrm/menu/rebuild&reset=1

Joomla 1.6 sites: http:///administrator/index.php?option=com_civicrm&task=civicrm/menu/rebuild&reset=1

Wordpress sites: http:///wp-admin/admin.php?page=CiviCRM&q=civicrm/menu/rebuild&reset=1

This action also resets the IDS (intrusion detection system) file.

b) As explained in @Tim Otten's answer, this can be done conveniently from the commandline as well, using a better named wrapper for the same actions:

In Civi-Drupal, the analogous command is: $ drush cvapi system.flush

In Civi-Wordpress, it's: $ wp civicrm api system.flush .

Or alternatively, in Firebug's CLI: CRM.api3('system','flush'))

  1. There are other sorts of caches that may occasionally need to be reset. a) At Contacts > Manage Groups, it is possible to reset the caches for contacts that are in Smart Groups by clicking near the top left of the page the Update Smart Group Counts link.

b) More generally, depending on the area of CiviCRM you are working on you may need to truncate any of the CiviCRM tables that have cache in their name:

mysql> show tables like '%cache%';
+-------------------------------------+
| Tables_in_clubcdn_civ_new (%cache%) |
+-------------------------------------+
| civicrm_acl_cache                   |
| civicrm_acl_contact_cache           |
| civicrm_cache                       |
| civicrm_group_contact_cache         |
| civicrm_prevnext_cache              |
+-------------------------------------+
5 rows in set (0.00 sec)

Use TRUNCATE civicrm_acl_cache; or similar queries on the command line or in phpMyAdmin to clear these tables.

  1. CMSes have their own caches that can often cause grief when developing in CiviCRM. For example, in Drupal 7, go to Configuration > and in Development set of modules click on Performance. Click to purge the caches. You might also want to disable caching of pages for anonymous users, caching of blocks, and / or aggregrating and compressing css and javascript files.
9

+1 for Joe's comment which is pretty thorough.

Re: drush cc all -- this command can be pretty important in the workflow for Drupal dev. In Civi-Drupal, the analogous command is drush cvapi system.flush In Civi-Wordpress, it's wp civicrm api system.flush . (Or, if you're more into Firebug's CLI, CRM.api3('system','flush'))

Note: Despite the anachronistic naming, "/civicrm/menu/rebuild" is basically the same thing, and so is "/civicrm/clearcache". Internally, all of these commands are wrappers for CRM_Core_Invoke::rebuildMenuAndCaches() (aka the grand-daddy of all flushing functions in Civi).

If there are any caches in the civicrm-core codebase that are omitted by CRM_Core_Invoke::rebuildMenuAndCaches(), then that's a bug, and patches to flush more caches would be welcome.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.