我通过在main.php文件中添加此代码来启用php中的dbcache
'cache'=>array(
'class'=>'system.caching.CDbCache',
'connectionID'=>'db',
),
现在我想为此缓存定义依赖性以检查上次更新的记录,但我无法执行此操作。
查询是: -
public function actionProductList()
{
$model=new Product();
$main=array();
/* $random =Product::model()->find(array(
'select'=>'MAX(update_time)',
));
$dependency =new CDbCacheDependency($random);
var_dump($random);*/
$productList1=Product::model()->cache(60)->with('productimages')->findAll();
foreach($productList1 as $productList)
{
$main1=array();
foreach($productList->productimages as $list)
{
if($list->isProfileImage==1)
{
$main1[]=array("path"=>$list->path,"imageId"=>$list->imageId);
}
}
if($productList->isPublish==1)
{
$main[]=array("productId"=>$productList->productId,"productName"=>$productList->productName,
"brandId"=>$productList->brandId,"mrp"=>$productList->mrp,
"isTaxInclude"=>$productList->isTaxInclude,"isAvailable"=>$productList->isAvailable,
"isFreeDelivery"=>$productList->isFreeDelivery,"description"=>$productList->description,
"isPublish"=>$productList->isPublish,"publishDate"=>$productList->publishDate,
"isActive"=>$productList->isActive,"userId"=>$productList->userId,
"createDate"=>$productList->createDate,"ipAddress"=>$productList->ipAddress,
"offerPrice"=>$productList->offerPrice,"manufactureId"=>$productList->manufactureId,"proimage"=>$main1);
}
}
echo"{\"Product\":".CJSON::encode($main)."}";
}
我在产品表中没有update_time字段,所以我如何实现此查询的依赖...
答案 0 :(得分:0)
您应该解释您尝试过的内容以及您想要缓存的内容。 manual中还有一个基本示例:
$dependency = new CDbCacheDependency('SELECT MAX(update_time) FROM tbl_post');
$posts = Post::model()->cache(1000, $dependency)->findAll();