2013-08-02 70 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