Is there a way to tell Drupal not to cache a specific page?
I have a custom php page that processes a feed of images and makes albums out of it. However whenever i add pictures to my feed, the Drupal page doesn't change until I clear the caches.
Is there a way to tell Drupal not to cache that specific page?
Thanks, Blake
Edit: Drupal v6.15 Not exactly sure what you mean oswald, team2648.com/media is hte page. I used the php interpreter module. Here is the php code:
<?php
//////// CODE by Pikori Web Designs - pikori.org ///////////
//////// Please do not remove this title, ///////////
//////// feel free to modify or copy this software ///////////
$feedURL = 开发者_如何学Go'http://picasaweb.google.com/data/feed/base/user/Techplex.Engineer?alt=rss&kind=album&hl=en_US';
$photoNodeNum = 4;
$galleryTitle = 'Breakaway Pictures';
$year = '2011';
?>
<?php
/////////////// DO NOT EDIT ANYTHING BELOW THIS LINE //////////////////
$album = $_GET['album'];
if($album != ""){
//GENERATE PICTURES
$feedURL= "http://".$album."&kind=photo&hl=en_US";
$feedURL = str_replace("entry","feed",$feedURL);
$sxml = simplexml_load_file($feedURL);
$column = 0;
$pix_count = count($sxml->channel->item);
//print '<h2>'.$sxml->channel->title.'</h2>';
print '<table cellspacing="0" cellpadding="0" style="font-size:10pt" width="100%"><tr>';
for($i = 0; $i < $pix_count; $i++) {
print '<td align="center">';
$entry = $sxml->channel->item[$i];
$picture_url = $entry->enclosure['url'];
$time = $entry->pubDate;
$time_ln = strlen($time)-14;
$time = substr($time,0,$time_ln);
$description = $entry->description;
$tn_beg = strpos($description, "src=");
$tn_end = strpos($description, "alt=");
$tn_length = $tn_end - $tn_beg;
$tn = substr($description, $tn_beg, $tn_length);
$tn_small = str_replace("s288","s128",$tn);
$picture_url = $tn;
$picture_beg = strpos($picture_url,"http:");
$picture_len = strlen($picture_url)-7;
$picture_url = substr($tn, $picture_beg, $picture_len);
$picture_url = str_replace("s288","s640",$picture_url);
print '<a rel="lightbox[group]" href="'.$picture_url.'">';
print '<img '.$tn_small.' style="border:1px solid #02293a"><br>';
print '</a></td> ';
if($column == 4){ print '</tr><tr>'; $column = 0;}
else $column++;
}
print '</table>';
print '<br><center><a href="media">Return to album</a></center>';
} else {
//GENERATE ALBUMS
$sxml = simplexml_load_file($feedURL);
$column = 0;
$album_count = count($sxml->channel->item);
//print '<h2>'.$galleryTitle.'</h2>';
print '<table cellspacing="0" cellpadding="0" style="font-size:10pt" width="100%"><tr>';
for($i = 0; $i < $album_count; $i++) {
$entry = $sxml->channel->item[$i];
$time = $entry->pubDate;
$time_ln = strlen($time)-14;
$time = substr($time,0,$time_ln);
$description = $entry->description;
$tn_beg = strpos($description, "src=");
$tn_end = strpos($description, "alt=");
$tn_length = $tn_end - $tn_beg;
$tn = substr($description, $tn_beg, $tn_length);
$albumrss = $entry->guid;
$albumrsscount = strlen($albumrss) - 7;
$albumrss = substr($albumrss, 7, $albumrsscount);
$search = strstr($time, $year);
if($search != FALSE || $year == ''){
print '<td valign="top">';
print '<a href="/node/'.$photoNodeNum.'?album='.$albumrss.'">';
print '<center><img '.$tn.' style="border:3px double #cccccc"><br>';
print $entry->title.'<br>'.$time.'</center>';
print '</a><br></td> ';
if($column == 3){
print '</tr><tr>'; $column = 0;
} else {
$column++;
}
}
}
print '</table>';
}
?>
Thanks for your answer.
The site you linked gave me some new verbiage to search with, and thus I found this: http://www.drupalcoder.com/story/365-disable-drupals-page-cache-for-some-pages
which then led me to this: http://drupal.org/project/cacheexclude
which did exactly what I wanted.
Hope this helps.
That is for Drupal 6.
This doesn't answer your specific question about caching, but -- consider using Drupal-native solutions like the Picasa module for things like this.
When you use non-Drupal PHP applications in a Drupal environment like you have here, you get weird interactions with other Drupal components. Drupal modules are build with Drupal in mind, so things like sane caching usually come built in.
Write this code line at the top of the custom page you dont want to be cached:
$GLOBALS['conf']['cache'] = FALSE;
For Drupal 6,
If you just want to exclude a specific page from being cached then you can use Cache exclude module, where you just have to provide a url.
for drupal 7 also it is available but its in the development version.
Yes you can do it programmatically and the below code is valid for Drupal 6 and 7 both.
Reference : http://techrappers.com/post/27/how-prevent-javascript-and-css-render-some-drupal-pages
/**
* Implements hook_init().
*/
function MODULE_NAME_init() {
global $conf;
// current_path() is the path on which you want to turn of JS or CSS cache
if (current_path() == 'batch' || current_path() == 'library-admin') {
// If you want to force CSS or JS cache to turned off
$conf['preprocess_js'] = FALSE;
$conf['preprocess_css'] = FALSE;
// If you want normal caching to turned off
drupal_page_is_cacheable(FALSE);
}
}
Please Note that drupal_page_is_cacheable(FALSE); can only turn off normal caching, it will not force JS caching to be turned off automatically unless you use $conf['preprocess_js'] = FALSE.
精彩评论