Ability to specify URL alias as well
hongbo - June 7, 2008 - 05:22
| Project: | CacheExclude |
| Version: | 6.x-2.0 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | mbutcher |
| Status: | closed |
Description
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;
}
}
#1
#2
Can you file a proper patch? Thanks. http://drupal.org/diffandpatch
#3
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;
}
}
#4
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.
#5
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;
}
}
#6
Do not copy and paste a patch into the form. Create a patch file and attach it.
#7
Ok, patch attached.
#8
#9
There was an error when pathing the file.
patch unexpectedly ends in middle of lineHunk #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.
#10
A minor variation of JoepH's patch has been committed, and will be available in 6.x-2.1. Thanks hongbo and JoepH!
#11
Automatically closed -- issue fixed for 2 weeks with no activity.
#12
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...
#13
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;
#14
The 5.x release is in maintenance mode only and is not taking new features.
#15
Automatically closed -- issue fixed for 2 weeks with no activity.