2012-08-10 102 views
3

我有一個塊顯示來自外部站點的RSS提要列表。我想繼續緩存除提到的塊之外的其他塊。怎麼做?以編程方式更改緩存設置在drupal 7

例如,我有blockA,bllockB和blockC。我只想將blockB的緩存設置更改爲DRUPAL_NO_CACHE並保留其他塊,因爲它們是我想要以編程方式執行的。

回答

4

您可以更改創建youre block的特定模塊中的高速緩存角色。 在下面的區塊信息中:

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, 
    ), 
); 
} 
0

這將通過將性能設置頁面(admin/settings/performance) &點擊向下滾動

但要確保「清除緩存數據」減少工作,這個頁面只由管理員

訪問爲Drupal 7是相同的作爲Drupal 6

<?php 
    drupal_flush_all_caches(); 
    drupal_set_message('cache flushed.'); 
?> 
+0

我很抱歉這麼ununderstandable – eyurdakul 2012-08-10 09:58:14

0

塊從哪裏來?這很重要。正如Jurgo所說,如果它是一個自定義模塊,您可以在hook_block_info中指定它。如果它們是視圖塊,則視圖中的每個顯示都會有一個緩存設置來處理這個問題。如果它們是由其他模塊提供的塊,則需要直接查詢數據庫以更改塊的緩存設置。

作爲一般說明,要顯示RSS源,只需使用「源」和「視圖」即可。那麼你根本就不會爲此編寫自定義代碼。

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; 
} 
相關問題