2013-08-02 30 views
1
I am trying to display random testimonials, but due to magento cache the random is not working, i have to flush the cache each time to see the testimonials change, my code 

public function getTestimonialsLast(){ 
     $collection = Mage::getModel('testimonial/testimonial')->getCollection(); 
     $collection->getSelect()->order(new Zend_Db_Expr('RAND()')); 
     $collection->addFieldToFilter('status',1); 
     $collection->setPageSize(5); 
     return $collection; 
    } 

我怎樣才能使它工作,我怎樣才能使它隨時刷新收集是隨機的。 任何幫助,不勝感激。 謝謝你在前進,越來越隨機推薦在magento由於緩存不工作

+0

在哪座你使用這種方法嗎? –

回答

2

一種可能性是在視圖文件:

您可以通過添加參數,當你執行塊緩存塊停止Magento的。

<?php echo $this->getChildHtml('testimonials', false) ?> 

因爲

Method Summary 
string getChildHtml ([string $name = ‘’], [boolean $useCache = true], [ $sorted = true]) 

或者你可以在緩存生存添加到您的推薦類:

public function getCacheLifetime() { return null; } 
0

你緩存模塊內的塊公共職能__construct()

它將對「cache_lifetime」

刪除緩存塊會防止它被緩存的信息和每次執行一次新的呼叫。

+0

不,沒有關於'cache_lifetime'的信息以及模塊中的公共函數__construct(){this_> init('testimonial'); \t} – jarus