有没有办法告诉Drupal不要缓存特定的页面?

时间:2011-01-12 16:37:35

标签: php drupal rss picasa

我有一个自定义的php页面,用于处理图像供稿并从中制作相册。但是,无论何时我将图片添加到我的Feed中,Drupal页面都不会更改,直到我清除缓存。

有没有办法告诉Drupal不要缓存该特定页面?

谢谢, 布雷克

编辑:Drupal v6.15 不完全确定你的意思oswald,team2648.com / media是hte页面。 我使用了php解释器模块。这是php代码:

    <?php
//////// CODE by Pikori Web Designs - pikori.org   ///////////
//////// Please do not remove this title,          ///////////
//////// feel free to modify or copy this software ///////////
$feedURL = '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>';
}
?>

6 个答案:

答案 0 :(得分:2)

Hope this helps.

这是Drupal 6。

答案 1 :(得分:2)

感谢您的回答。

您链接的网站给了我一些新的搜索词,因此我发现了这个: http://www.drupalcoder.com/story/365-disable-drupals-page-cache-for-some-pages

然后引导我到这个: http://drupal.org/project/cacheexclude

这完全符合我的要求。

答案 2 :(得分:1)

这不能回答您关于缓存的具体问题,但是 - 考虑使用像Picasa模块这样的Drupal原生解决方案。

当您在Drupal环境中使用非Drupal PHP应用程序时,您会遇到与其他Drupal组件的奇怪交互。 Drupal模块是在考虑Drupal的情况下构建的,因此通常会内置sane缓存等内容。

答案 3 :(得分:1)

将此代码行写在您不想缓存的自定义页面的顶部:

$GLOBALS['conf']['cache'] = FALSE;

答案 4 :(得分:0)

对于Drupal 6,

如果您只想排除某个特定页面被缓存,那么您可以使用缓存排除模块,您只需提供一个网址。

对于drupal 7也可用,但它在开发版本中。

答案 5 :(得分:0)

是的,你可以通过编程方式完成,下面的代码对Drupal 6和7都有效。

参考: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); 
  } 
}

请注意drupal_page_is_cacheable(FALSE);只能关闭正常缓存,除非你使用$ conf ['preprocess_js'] = FALSE,否则它不会强制自动关闭JS缓存。