Clearing out cached data and image styles (cache-clear and image-flush)

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.

Flushing the cache

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.

Deleting generated images from an image style

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:

  1. A view is created listing node images using the image style thumbnail.
  2. A few nodes are created populating our list. It is looking good so far. All the thumbnails of our nodes are being generated at sites/default/files/images/thumbnail.
  3. The designer kicks in, reviews the website, and yells, horrified! He/she starts theming the site and updates the thumbnail image style with a smaller scale.
  4. Some of the pages which have images using the 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]

Note

Drupal 6 uses the contributed module Imagecache, which defines a couple of Drush commands that perform the same task as explained previously.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.9.115