Hi,
what will be best way to cache a query result
Table: category {id:int, name:varchar}
so what will be better in performance?
$dependency = new CDbCacheDependency('SELECT MAX(id) FROM category');
OR
Normal way to cache
public static function myGetAll()
{
$id = 'categories';
$sql = 'SELECT * FROM '.self::tableName().' ORDER BY name ASC';
$value=Yii::app()->cache->get($id);
if($value===false)
{
$value = Yii::app()->db->createCommand($sql)
/*->select()
->from(self::tableName())*/
->queryAll();
Yii::app()->cache->set($id,$value);
}
return $value;
}
setting a very long time lime limit or unlimited and when a new category got added by and admin, updates and refresh categorys cache?
Thanks