Currently we can only exclude pages using Drupal path, such as node/10, blog/23, etc..

Would it be easier if we can exclude pages using URL alias, such as 'my-dynamic-page'.

I have the code for it, here is the new cacheexclude_init() for file cacheexclude.module.
Added: OR drupal_match_path(substr($_SERVER['QUERY_STRING'],2), $pages)

function cacheexclude_init() {
  $pages = trim(variable_get('cacheexclude_list', ''));
  // If the current page is one we want to exclude from the cache, 
  // set the page caching to false temporarily.
  
//if (strlen($pages) && drupal_match_path($_GET['q'], $pages)) { //replace this with next 2 lines
  if (strlen($pages) && (drupal_match_path($_GET['q'], $pages) || 
      drupal_match_path(substr($_SERVER['QUERY_STRING'],2), $pages) )) {
    $GLOBALS['conf']['cache'] = FALSE;
  }
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hongbo’s picture

Version: 6.x-2.x-dev » 6.x-2.0
Crell’s picture

Status: Needs review » Active

Can you file a proper patch? Thanks. http://drupal.org/diffandpatch

hongbo’s picture

Status: Active » Needs review

Here is proper patch, and it only change ONE line.

--- cacheexclude.module.old     2008-02-22 06:38:00.000000000 +1000
+++ cacheexclude.module 2008-06-20 10:26:10.000000000 +1000
@@ -38,7 +38,8 @@ function cacheexclude_init() {
   $pages = trim(variable_get('cacheexclude_list', ''));
   // If the current page is one we want to exclude from the cache,
   // set the page caching to false temporarily.
-  if (strlen($pages) && drupal_match_path($_GET['q'], $pages)) {
+  if (strlen($pages) && (drupal_match_path($_GET['q'], $pages) ||
+                         drupal_match_path(substr($_SERVER['QUERY_STRING'],2), $pages) )) {
     $GLOBALS['conf']['cache'] = FALSE;
   }
 }
Crell’s picture

Status: Needs review » Needs work

Don't access $_SERVER['QUERY_STRING'] directly. That's more error-prone. It's better and more portable to call drupal_get_path_alias($_GET['q']), as that ties into the aliasing system directly.

hongbo’s picture

Status: Needs work » Needs review

Ok, drupal_get_path_alias($_GET['q']) works. Here is the modified patch

--- cacheexclude.module.old     2008-02-22 06:38:00.000000000 +1000
+++ cacheexclude.module 2008-06-21 15:10:00.000000000 +1000
@@ -38,7 +38,8 @@ function cacheexclude_init() {
   $pages = trim(variable_get('cacheexclude_list', ''));
   // If the current page is one we want to exclude from the cache,
   // set the page caching to false temporarily.
-  if (strlen($pages) && drupal_match_path($_GET['q'], $pages)) {
+  if (strlen($pages) && (drupal_match_path($_GET['q'], $pages) ||
+                         drupal_match_path(drupal_get_path_alias($_GET['q']), $pages) )) {
     $GLOBALS['conf']['cache'] = FALSE;
   }
}
Crell’s picture

Status: Needs review » Active

Do not copy and paste a patch into the form. Create a patch file and attach it.

hongbo’s picture

Ok, patch attached.

Crell’s picture

Status: Active » Needs review
joep.hendrix’s picture

There was an error when pathing the file.

patch unexpectedly ends in middle of line
Hunk #1 succeeded at 38 with fuzz 2.

The code itself works fine when manually applied.
Here is a new patch file with the same code but without the error.

mbutcher’s picture

Assigned: Unassigned » mbutcher
Status: Needs review » Fixed

A minor variation of JoepH's patch has been committed, and will be available in 6.x-2.1. Thanks hongbo and JoepH!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

lemuelsantos’s picture

Version: 6.x-2.0 » 5.x-2.x-dev
Status: Closed (fixed) » Patch (to be ported)

Please add this patch to Drupal 5 version;
No codes changes required I'm using the patch for Drupal 6 and it's working fine;
Thanks...

lemuelsantos’s picture

well... it needs to do a drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH) to get the function drupal_get_path_alias declared otherwise you are going to face a undefined function call;

Crell’s picture

Version: 5.x-2.x-dev » 6.x-2.0
Status: Patch (to be ported) » Fixed

The 5.x release is in maintenance mode only and is not taking new features.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.