Кеширование CActiveDataProvider - возможно ли?
Добавлено: 2010.09.20, 21:01
Собственно сабж. Можно ли кешировать CActiveDataProvider?
Форум Yii-программистов
https://yiiframework.ru/forum/
Код: Выделить всё
value=Yii::app()->cache->get($id);
if($value===false)
{
// обновляем $value, т.к. переменная не найдена в кэше,
// и сохраняем в кэш для дальнейшего использования:
// Yii::app()->cache->set($id,$value);
}
Код: Выделить всё
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_viewGoods',
)); ?>
если убрать кеширование то работаетTrying to get property of non-object
public function getTableSchema()
615 {
616 return $this->getMetaData()->tableSchema;
617 }
Nafania писал(а):По идее должно кешироваться вообще все что угодно, втч CActiveDataProvider.
Дайте побольше кода.
Код: Выделить всё
$dataProvider = new CActiveDataProvider(Goods::model()->notdeleted($id), array(
'pagination'=>array(
'pageSize'=>11
)
));
Yii::app()->cache->set("GoodsList{$id}",
$dataProvider,
$this->module->cacheDuration,
DBDependency::GetTbDependency(Goods::model()->tableName())
);
Код: Выделить всё
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_viewGoods',
)); ?>
Trying to get property of non-object
/home/konst/framework/db/ar/CActiveRecord.php(616)
604 */
605 public function getActiveRelation($name)
606 {
607 return isset($this->getMetaData()->relations[$name]) ? $this->getMetaData()->relations[$name] : null;
608 }
609
610 /**
611 * Returns the metadata of the table that this AR belongs to
612 * @return CDbTableSchema the metadata of the table that this AR belongs to
613 */
614 public function getTableSchema()
615 {
616 return $this->getMetaData()->tableSchema;
617 }
618
619 /**
620 * Returns the command builder used by this AR.
621 * @return CDbCommandBuilder the command builder used by this AR
622 */
623 public function getCommandBuilder()
624 {
625 return $this->getDbConnection()->getSchema()->getCommandBuilder();
626 }
627
628 /**
Код: Выделить всё
if(($dataProvider=Yii::app()->cache->get("GoodsList{$id}"))===false)
{
$dataProvider = new CActiveDataProvider(Goods::model()->notdeleted($id), array(
'pagination'=>array(
'pageSize'=>11
)
));
Yii::app()->cache->set("GoodsList{$id}",
$dataProvider->getData(),
$this->module->cacheDuration,
DBDependency::GetTbDependency(Goods::model()->tableName())
);
}
else
$dataProvider=new CArrayProvider($dataProvider);
$dataProvideer->getData() возвращает массив данных (без объекта сортировки, погинации, только данные)zibert02 писал(а):to mc-bear
не совсем понял ваш код
когда изучал вопрос по кешированию провайдера то наткнулся на какоето крутое расширение для кеширования , только вот не помню адресаmc-bear писал(а):А что тогда смотрел zibert02 ?
может вспомнишь, хотел бы посмотретьzibert02 писал(а):только вот не помню адреса