Trying to exclude certain types of nodes from the authcache by creating a custom ruleset. Problem is, I'm playing "guess and try" to see what global variables (get/post/request/session/etc) are available through that code. Any hints?

Comments

Jonah Ellison’s picture

The PHP code is evaluated within the drupal_eval function. It adds the global variables $theme_path, $theme_info, $conf. You can also add global $user; and so on to access more global variables, and you can also call Drupal functions. It's pretty much like any other part of Drupal that allows PHP code.

wrightnow’s picture

Jonah, excellent response - I'm fairly new to Drupal and finding a coherent documentation source is a challenge.

Since you definitely have far more experience with the AuthCache ruleset system than I, do you have a suggestion for how to exclude certain CCK types (nodes) from caching? Or, alternatively, specify distinct CCK types to include in the cache? The default variables ($conf, $GLOBALS,$user) don't seem to point to the current node...

Jonah Ellison’s picture

Sure, here is an example:

$types = array('blog', 'news', 'story'); // node types to exclude

if(arg(0) == 'node' && is_numeric(arg(1)) { // node page?
  $node = node_load(arg(1));
  if (in_array($node->type, $types)) {
    return FALSE;
  }
}

wrightnow’s picture

Thought I'd post the solution I came up with. For our site, 99% of our nodes are of a single CCK type, so we only need/want to cache those (The rest are dynamic). My solution was to add the following to our page.tpl.php rather than find a solution through the rulesets.

if ($node->type != 'FOO') {
    global $is_page_authcache;
    $is_page_authcache = FALSE;
}

I'm very open to comments...

Jonah Ellison’s picture

Yep, that can work as well, jww2nc.

There are many ways to do things in Drupal, though I would following certain standards. One is limiting code logic in template files in order to leave them as clean as possible for theming. I usually try to add theme logic to template.php. For example, you can use a preprocess function, like function YOURTHEME_preprocess_node(&$variables) { } to set $is_page_authcache to false (YOURTHEME_preprocess_page() can work as well, since $variables['node'] contains the node object).

wrightnow’s picture

Status: Active » Closed (fixed)

Excellent! I'm very familiar with the preprocess hooks.

Jonah, you've been very helpful - I very much appreciate the amazingly prompt responses. I'm going to close this issue since you've answered all my questions - hopefully thats the right procedure on Drupal boards...