
We’re excited to hear your project.
Let’s collaborate!
The Earth is round, a buttered toast will always fall butter-side down and doing clear cache is every Drupal developer's best practice, these are all globally-accepted truths! And speaking of the latter, when you discover that the familiar Drush clear cache technique is no longer universally unique you wonder: why the change?
Why go from clear-cache, to... actually rebuilding cache, starting with Drupal 8?
What's the catch?
This new way to clear Drupal cache must be stemming from a certain limitation that earlier versions of Drupal presented:
Partially completed cache-clearing operations threatening to grow into fatal errors.
And now, let's dig into more details on:
So, shall we proceed?
First of all, here's the “motivation” that drives Drupal to create a cache in the first place:
Each time a Drupal site has to render a certain web page, it is “forced” to perform specific database queries; and since all these queries have a negative impact on the overall page loading time, Drupal “decides” to store these web pages, once it will have rendered them, in a cache for later (streamlined) reference.
OK, now that we've settled this whole “cause and effect” process, let's see why and when you should clear cache on your Drupal site:
In a few words: clearing your cache might just be one of the most frequent actions you'll take while working (or simply maintaining) on a Drupal site.
And in many cases, the one that will “save the day”, without the need to apply other more complex techniques from your “arsenal”.
For there are several ways for you to clear your Drupal site's cache. Just go with the one that best suits your work style:
By far the handiest (and some might say “the less-efficient”, too) method to clear Drupal cache is via the UI:
It won't be long till Drupal displays the “Caches cleared” message for you! And that's it!
And now, the second method in your “arsenal”: the clear Drupal cache command line one!
A two-way method, better said, which depends greatly on the version of Drupal on your website: 7 or 8?
In this respect, here's the “magic command” to use for clearing your Drupal 7's cache:
drush cache-clear all
or
drush cc all
Whereas in Drupal 8, this is the Drush command for tackling your cache:
drush cache-rebuild
or, alternatively, these 2 aliased commands:
drush rebuild or drush cr
And here I'm sure you can already tell which are the specific steps to take for handling your cache in Drupal 8 using Drush (still the most convenient way to do it):
Among all the improvements that Drupal 8 “lures” us in with (built-in WYSIWYG, a Twig templating system and so on), there's the /core/rebuild.php file standing out!
And “promising” us to streamline our frequent (and time-consuming) cache tackling tasks that we need to carry out during development:
The Drupal 8 site in question doesn't even have to be working and the whole process doesn't require Drupal Console or Drush either!
How about that?
The one and only requirement (for there still is one) is that your site's configuration supports it.
And how can you check whether your site's config accepts this functionality? Well, there 2 methods at your disposal:
And voila! This “trick” will rebuild all cache without even requiring for the Drupal 8 site itself to be working during the whole process!
Which makes it the perfect “plan B”, whenever you don't have Drupal Console or Drush installed where you're working!
The only condition is that your websites' configuration supports this functionality!
Spoiler alert: by “truncate” I do mean emptying, not removing!
The fourth method to clear Drupal cache involves clearing all the data from the cache-related tables in your database. Meaning all the tables starting with “cache_”.
For this, you just go over to your phpMyAdmin, select all the cache_* table and then click “Truncate” in the “with selected” drop-down menu placed at the bottom of the page:
TRUNCATE cache_config;
TRUNCATE cache_container;
TRUNCATE cache_data;
TRUNCATE cache_default;
TRUNCATE cache_discovery;
TRUNCATE cache_dynamic_page_cache;
TRUNCATE cache_entity;
TRUNCATE cache_menu;
TRUNCATE cache_render;
TRUNCATE cache_toolbar;
As for the command line, feel free to scan through and then to tap into the valuable info that you'll find here: https://goo.gl/1b4otB here's another practical example:
Let's say it's Sequel Pro — an SQL GUI app — that you're using. For truncating those specific tables, connect to the server, track down your site's database, have those specific “cache_” tables highlighted and just choose “Truncate tables”, from the drop-down menu!
Also, in the above-mentioned “scenario” you could alternatively go to your PhPMyAdmin's SQL command field or MySQL CLI and run the above-mentioned command:
Here's the challenge that the conventional Drush clear cache (or “drush cc all”) used to make us deal with:
Drupal's using caching intensively and therefore, it implicitely creates lots of inter-dependencies. Only partially flushing this heavy load of caches used to pose some major risks for any website.
This is where the “cache-rebuild” method stepped in, starting with Drupal 8!
It practically rebuilds (re-bootstraps) the whole Drupal site, after making sure that all cache is perfectly cleared. A “check and double check” technique, you may call it, which makes sure that:
Drupal 7's so very popular Drush cache command itself gets cleared and replaced with “cache-rebuild” in Drupal 8.
Which (the Drush cache-rebuild command specific to Drupal 8) carries out the following tasks:
Summing it up now, the essential info to remember is that:
We’re excited to hear your project.
Let’s collaborate!