$dependency = new CDbCacheDependency('SELECT MAX(update_time) FROM tbl_post');
Is a dependency. It is used to invalidate the cache when there are changes to the underlying table.
To cache a query, try:
$connection=Yii::app()->db;
$command=$connection->createCommand();
$dependency = new CDbCacheDependency('select count(*) from user'); // Set your dependency.
$connection->cache(60, $dependency); // Set your cache duration.
$content=$command->select('*')
->from('user')
->queryAll();
$dependency = new CDbCacheDependency(‘select count(*) from user’); // Set your dependency.
[color="#4B0082"][font=“Arial Black”]here 'select count(*) from user ,don’t you write it wrong, it should be select * from user ,shouldn’t it?,must the sql be same as the sql query i need to cache?[/font][/color]
$connection->cache(60, $dependency); // Set your cache duration.
The query for the cache dependency should be a simple query to detect the changes to your table, e.g. max timestamp, or some value that changes every time the table data is modified. Doing a ‘select * from user’ may not be a good candidate.