Drupal's cache and image styles are very frequently recreated in the early stages of a project. On one hand, new menu entries are added, blocks are removed, and features are reverted among others. On the other, image styles are created and then modified several times so the images that use them suit new design requirements. These two can be cleared out with simple and very similar commands.
Clearing out the cache is one of the most common tasks in a Drupal site. Drupal has a few cache tables which share the same structure and are used to store data of a particular nature. Drush comes with a handy command for clearing out these tables: cache-clear
. Without arguments, it prompts with the list of available cache types that can be cleared out:
$ cd /home/juampy/projects/drupal
$ drush cache-clear
Enter a number to choose which cache to clear.
[0] : Cancel
[1] : all
[2] : theme registry
[3] : menu
[4] : css+js
[5] : block
[6] : module list
[7] : theme list
[8] : registry
[9] : views
9
'views' cache was cleared [success]
In the previous example, we cleared the Views cache. As a shortcut, we can pass the cache type to the command itself:
$ drush cache-clear menu
'menu' cache was cleared [success]
$ drush cache-clear "theme registry"
'theme registry' cache was cleared [success]
$ drush cache-clear all
'all' cache was cleared [success]
In production sites with a high demand of traffic, flushing all cache types could be catastrophic for the site's performance. Therefore, picking the right cache to clear in these scenarios is a wise practice.
An image style is used to generate different displays out of an image (for example, a thumbnail or an unsaturated version). It is very common to start a Drupal project and use the default image styles (thumbnail, medium, and small). However, once the theming process starts, these are normally modified to suit better needs. But what about all the images that were already uploaded to the site and thus generated through the existing image styles? Here is a practical scenario:
thumbnail
. sites/default/files/images/thumbnail
. thumbnail
image style with a smaller scale. thumbnail
image style are not reflecting this change. Here is how you could flush all these images:$ drush image-flush thumbnail
Image style thumbnail flushed [success]
If you want to clean all image styles in the system, pass the argument all
to the command. You can also make it print a list of available options to choose from:
drush image-flush
Choose a style to flush.
[0] : Cancel
[1] : all
[2] : thumbnail
[3] : medium
[4] : large
1
All image styles flushed [success]
52.14.82.217