Site Building

12.2. Clearing the Cache for Drupal 8, 9, and 10

Goal

Clear or rebuild your site’s internal caches to ensure they are up-to-date with the most recent data, using the user interface or Drush.

Site prerequisites

If you want to use Drush to clear the cache, Drush must be installed. See Section 3.2, “Concept: Additional Tools”.

Steps

Sprout Video

You can use the administrative interface or Drush to clear the cache. You can also use the rebuild script or Drush to do a more complete cache rebuild.

Using the administrative interface to clear the cache

  1. In the Manage administrative menu, navigate to Configuration > Development > Performance (admin/config/development/performance). If you cannot access this page in the administrative interface, use one of the other methods to clear or rebuild the cache.
  2. Click Clear all caches.
  3. A message saying the cache has been cleared appears at the top of the page.
  4. If this doesn’t resolve the problem that caused you to want to clear the cache, try a rebuild instead.

Using the rebuild script

  1. Open settings.php (/sites/default/settings.php) in any plain text editor. Add this line to the end of the file and save it:

    $settings['rebuild_access'] = TRUE;
  2. Visit http://www.example.com/core/rebuild.php in your browser (where www.example.com is your site’s URL). After a short pause, you should be redirected to the home page of your site, and the cache should be rebuilt.
  3. Open settings.php (/sites/default/settings.php) in a text editor. Find the line you added with $settings[rebuild_access], remove this line, and save the file.

Using Drush to rebuild or clear the cache

You can use one of two commands:

  • Use the command drush cache:rebuild to clear and rebuild all cached data for a site. After running this command, you will see the output message "Cache rebuild complete."
  • Use the command drush cache:clear to see a list of individual caches and then choose the specific cache you would like to clear. Running this command should produce output like the following:

    > drush cache:clear
    Enter a number to choose which cache to clear.
     [0]  :  Cancel
     [1]  :  drush
     [2]  :  theme-registry
     [3]  :  menu
     [4]  :  css-js
     [5]  :  block
     [6]  :  module-list
     [7]  :  theme-list
     [8]  :  render
     [9]  :  views

Choose a cache to clear by entering the number associated with that cache. Press "Enter" to continue.

To clear a specific cache type, you can specify it in the cache:clear command. For example to clear the render cache:

drush cache:clear render

Additional resources

Drupal.org community documentation page "Clearing or rebuilding Drupal’s cache"

Attributions

Adapted and edited by Joe Shindelar and Jack Haas from "Clearing or rebuilding Drupal’s cache", copyright 2000-2024 by the individual contributors to the Drupal Community Documentation.