我有一个显示来自外部网站的RSS源列表的块。我想继续缓存除了提到的块之外的其他块。怎么做?
示例,我有blockA,bllockB和blockC。我只想永久地将blockB的缓存设置更改为DRUPAL_NO_CACHE并保留其他块,我想以编程方式执行此操作。
答案 0 :(得分:4)
您可以更改创建块的特定模块中的缓存角色。 在下面的块信息中:
function pref_block_info() {
return array(
'pref_main' => array(
'info' => t('Display flash game for auth. users'),
'cache' => DRUPAL_NO_CACHE,
),
'pref_winner' => array(
'info' => t('Show the winner of the last week.'),
'cache' => DRUPAL_NO_CACHE,
),
'pref_leader' => array(
'info' => t('Show the leader of the current week.'),
'cache' => DRUPAL_NO_CACHE,
),
'pref_top' => array(
'info' => t('Show the top 10 of the current week.'),
'cache' => DRUPAL_NO_CACHE,
),
);
}
答案 1 :(得分:2)
如果您在自己的模块中定义块,Jurgo给出的答案是完全正确的。
如果您想要更改由其他模块编写的块的缓存行为,则可以使用函数mymodule_block_list_alter
function mymodule_block_list_alter(&$blocks, $theme, $code_blocks) {
// Remove the caching on rss feeds block.
// Here rss-feeds is the unique key for the block
$blocks['rss-feeds']['cache'] = DRUPAL_NO_CACHE;
}
答案 2 :(得分:0)
这会通过转到效果设置页(admin/settings/performance)
&来减少工作量。通过向下滚动
但请确保此页面仅由管理员访问
对于Drupal 7与Drupal 6相同
<?php
drupal_flush_all_caches();
drupal_set_message('cache flushed.');
?>
答案 3 :(得分:0)
街区来自哪里?这很重要。正如Jurgo所说,如果它是自定义模块,您可以在hook_block_info中指定它。如果它们是视图块,则视图中的每个显示都有一个缓存设置来处理它。如果它们是某些其他模块提供的块,则需要直接查询数据库以更改块的缓存设置。
作为一般说明,要显示RSS源,只需使用“源和视图”。那么你根本就不会编写任何自定义代码。