Last updated February 1, 2011. Created by abraham on October 29, 2006.
Edited by SqyD, bekasu, sepeck, chx. Log in to edit this page.

Squid is a fully-featured, open-source web-content caching system. In accelerator mode, squid can be used in between your users and your web-server to cache objects and reduce requests against your web server(s) and database server(s).

Usually, Drupal has very dynamic content (nodes get comments and so on, the pages look different from one user to the other) and it has its own cache so Squid caching Drupal content is neither really desired nor really feasible. Drupal does supply the necessary headers which tells Squid not to cache its pages. However, images and other static content can be cached by Squid and usually it really helps.

For more information on setting up squid, please see http://www.squid-cache.org/.

Squid Caching and Dynamic Drupal Content

Squid Caching is not only for static content, but also can be used for dynamic content. The two events that one needs to focus on is node update and node delete. (of course, other types of content will require similar PURGE events). If these events are fired (node.module) then you need to send the squid server a PURGE event.

This can be accomplished with the purge and expire modules.

Below is a sample of code and discussion how to manually hack core.

if ($node->is_new) {
    // we may use this later to create a cached item
  }
  else {
    // this is the update event
    //   echo ' <p>node is being updated</p> ';
// purge squid cache
$output = exec('squidclient -m PURGE http://www.your_url_here.com:81/node/' .
$node->nid);
  }
  }

(assumptions: squid is processing all port 80 requests, thus I have set it up so the drupal page is on port 81)]

Similar code would also be required for the Node Delete event. If you are running Selinux (fc5,fc6) then you will may need to implement security policy changes so that this event, which is an external php call.

It is very important that you setup the correct rules inside of the squid.conf that define which content is not cached. For instance, you don't want a node edit page to be cached as it would result in the editing of the wrong content.

Needed - The sample code above assumes I'm hard coding the event inside the node.module. This a hack and not recommended. What are the proper API calls I need to implement so that this code may be move outside the node.module and into its own squid.module? You can refer to the squid url above for how to setup rules.

Drupal Cache: Squid is extremely scalable. Drupal's use of squid as part of the front ending solutions in concert with an internal caching strategy will massively increase scalability. Just a thought.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.