Posted by markwk on October 27, 2011 at 11:49am
I'm currently using omega8 hosting with nginx and all that sped-up goodness. I'm developing a bunch of stuff with node.js integration now, and I have a chat node that needs to have caching disabled. Basically a user can chat live and all that via node.js backend but when they reload the page it's pulling the cached page a not the recent chat.
So how would one go about disabling caching for a single node type, for example?
I saw something about: header('X-Accel-Expires: 0'); in the nginx google group forums but I'm really sure how or where to apply this in my module.

Comments
omega8cc Hosting
Method 1:
In your Drupal settings.php you will have something like this (my shown version will differ from yours - but will suite for illustration purposes):
<?php
//
// X-Accel-Expires: Sets when to expire the file in the internal Nginx cache, if one is used.
// We emit an "X-Accel-Expires: 0" header when a user is logged in or has taken actions that should cause them to get a customized page
//
if (isset($<em>SERVER['HTTP_HOST'])) { // If HTTP_HOST is not set, client is either old (HTTP 1.0) or has made a request directly to our web site's IP
if (preg_match("/\/(?:files\/advagg</em>|files\/styles|files\/imagecache)/", $<em>SERVER['REQUEST_URI'])) { // if static files (via: advagg || imagecache || files || styles|files)
header('X-Accel-Expires: 0'); // do not cache it on the Nginx cache level
}
if (isset($_SERVER['REQUEST_TIME']) && isset($_SERVER['REMOTE_ADDR']) && isset($_SERVER['HTTP_USER_AGENT']) && // If timestamp for start of the request + User-agent
!preg_match("/\/(?:files\/advagg</em>|files\/styles|files\/imagecache)/", $_SERVER['REQUEST_URI'])) { // + NOT static files
$identity = $_SERVER['REQUEST_TIME'] . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_HOST'] . $_SERVER['HTTP_USER_AGENT']; // create and ID
$identity = 'BOND'. md5("$identity");
$test_sess_name = 'SESS'. md5($cookie_domain); // create a session cookie
if (preg_match("/^\/(?:user|admin|logout)/", $_SERVER['REQUEST_URI']) ||
preg_match("/\/(?:node\/[0-9]+\/edit|node\/add|comment\/reply|approve|users)/", $_SERVER['REQUEST_URI'])) { // Admin or User or dynamics
header('X-Accel-Expires: 0'); // do not cache it on the Nginx cache level
if (isset($_COOKIE[$test_sess_name]) && !isset($_COOKIE['OctopusNoCacheID'])) {
setcookie('OctopusNoCacheID', $identity, $_SERVER['REQUEST_TIME'] + ('240' + 60), '/', $cookie_domain);
}
elseif (!isset($_COOKIE[$test_sess_name]) && !isset($_COOKIE['OctopusNoCacheID'])) {
setcookie('OctopusNoCacheID', 'NOCACHE' . $identity, $_SERVER['REQUEST_TIME'] + ('240' + 60), '/', $cookie_domain);
}
}
elseif (isset($_COOKIE[$test_sess_name]) && !isset($_COOKIE['OctopusCacheID'])) {
setcookie('OctopusCacheID', $identity, $_SERVER['REQUEST_TIME'] + ('86400' + 300), '/', $cookie_domain);
header('X-Accel-Expires: 300');
}
elseif (isset($_COOKIE[$test_sess_name]) && isset($_COOKIE['OctopusCacheID'])) {
header('X-Accel-Expires: 300');
}
elseif (!isset($_COOKIE[$test_sess_name]) && isset($_COOKIE['OctopusCacheID'])) {
setcookie('OctopusCacheID', 'NOCACHE' . $identity, $_SERVER['REQUEST_TIME'] + ('0' + 60), '/', $cookie_domain);
header('X-Accel-Expires: 0');
}
}
}
?>
Now, add your node path to this line:
<?phpif (preg_match("/^\/(?:user|admin|logout)/", $_SERVER['REQUEST_URI']) ||
preg_match("/\/(?:node\/[0-9]+\/edit|node\/add|comment\/reply|approve|users)/", $_SERVER['REQUEST_URI'])) { // Admin or User or dynamics
?>
Method 2:
Method 3:
For further reference, see: http://groups.drupal.org/node/157779
You are correct about the use of
header('X-Accel-Expires: 0')<?phpif (preg_match("/^\/(?:user|admin|logout)/", $_SERVER['REQUEST_URI']) ||
preg_match("/\/(?:node\/[0-9]+\/edit|node\/add|comment\/reply|approve|users)/", $_SERVER['REQUEST_URI'])) { // Admin or User or dynamics
header('X-Accel-Expires: 0')
?>
Reference: see -> http://techminded.net/blog/transparent-cache-in-nginx.html
--
Linux: Web Developer
Peter Bowey Computer Solutions
Australia: GMT+9:30
(¯`·..·[ Peter ]·..·´¯)
Option 4#: From the original
Option 4#:
From the original omega8cc archives:
see: http://drupal.org/node/1157024#comment-4468508
So use something like this:
<?php
# override global settings.php
if (preg_match("/^\/(?:quiz|anyname)/", $_SERVER['REQUEST_URI'])) {
header('X-Accel-Expires: 0'); // do not cache it in the speed booster
}
?>
--
Linux: Web Developer
Peter Bowey Computer Solutions
Australia: GMT+9:30
(¯`·..·[ Peter ]·..·´¯)
It should be possible not
It should be possible not only in the module, but even in your theme - at the top of page.tpl.php, where you could conditionally add the header
header('X-Accel-Expires: 0');only for expected content type, on the fly. It will be not the most elegant (or even correct?), but it should work anyway.A modest proposal
I have 0 knowledge about the specifics of omega8cc hosting secrete potion. My suggestion is for you to create a map that sets a variable and use that variable to bust the cache. Or, better yet, configure Nginx to have a location relative to the URIs not to be cached.
location ^~ /do/not/cache/here/ {# no caching here
}
You have to define an alias for that using pathauto.
I think there's room for a
I think there's room for a module that sends different cache times (or a zero cache time) for different parts of your site. The single setting under /admin/settings/performance may not fit every page. Sounds like a good use case for ctools page manager.