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

发布于 2024-10-12 03:22:05 字数 3596 浏览 3 评论 0原文

我有一个自定义 php 页面,用于处理图像提要并从中制作相册。然而,每当我将图片添加到提要中时,Drupal 页面都不会更改,直到我清除缓存。

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

谢谢, 布莱克

编辑:Drupal v6.15 不太确定你的意思奥斯瓦尔德,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>';
}
?>

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 = '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>';
}
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

平安喜乐 2024-10-19 03:22:05

感谢您的回答。

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

然后导致我这样做:
http://drupal.org/project/cacheexclude

这正是我想要的。

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.

开始看清了 2024-10-19 03:22:05

希望这会有所帮助。< /a>

这是针对 Drupal 6 的。

Hope this helps.

That is for Drupal 6.

櫻之舞 2024-10-19 03:22:05

这并没有回答您有关缓存的具体问题,但是 - 考虑使用 Drupal 原生解决方案,例如 Picasa类似这样的模块。

当您在像这里这样的 Drupal 环境中使用非 Drupal PHP 应用程序时,您会与其他 Drupal 组件进行奇怪的交互。 Drupal 模块是根据 Drupal 构建的,因此通常会内置诸如合理缓存之类的东西。

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.

长伴 2024-10-19 03:22:05

在您不想缓存的自定义页面的顶部写入以下代码行:

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

Write this code line at the top of the custom page you dont want to be cached:

$GLOBALS['conf']['cache'] = FALSE;
关于从前 2024-10-19 03:22:05

对于 Drupal 6,

如果您只想从缓存中排除特定页面,那么您可以使用缓存排除模块,只需提供一个 url 即可。

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

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.

生生不灭 2024-10-19 03:22:05

是的,您可以通过编程方式完成此操作,并且以下代码对于 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);只能关闭普通缓存,不会强制自动关闭JS缓存,除非使用$conf['preprocess_js'] = FALSE。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文