質問

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;
    }

how can i make it work , how can i make it so that whenever the page is refreshed the collection is randomized. Any help is greatly appreciated. Thank you in advance,

役に立ちましたか?

解決

One possibility is in the view file:

You can stop Magento from caching the block by adding a false parameter when you implement the block.

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

Because of

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

Or you could add the cache lifetime to your testimonial class:

public function getCacheLifetime() { return null; }

他のヒント

Are you caching the block within the modules public function __construct()

It would have information on 'cache_lifetime'

Removing the cache block would prevent it from being cached and perform a fresh call each time.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top