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

ページが更新されるたびにコレクションがランダム化されるようにするにはどうすればよいですか。どんな助けでも大歓迎です。前もって感謝します、

4

2 に答える 2

2

1 つの可能性はビュー ファイルにあります。

ブロックを実装するときにfalseパラメータを追加することで、Magento がブロックをキャッシュしないようにすることができます。

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

なぜなら

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

または、証明書クラスにキャッシュの有効期間を追加することもできます。

public function getCacheLifetime() { return null; }
于 2013-08-02T19:19:22.003 に答える
0

モジュール内でブロックをキャッシュしていますか public function __construct()

「cache_lifetime」に関する情報が含まれます

キャッシュ ブロックを削除すると、キャッシュされなくなり、毎回新しい呼び出しが実行されます。

于 2013-08-02T18:02:42.730 に答える