I added a file cache to an index view and it’s working great:
main.php
'components'=>array(
'cache'=>array(
'class'=>'system.caching.CFileCache',
),
PostController.php
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
'postOnly + delete', // we only allow deletion via POST request
array(
'COutputCache + index',
'requestTypes' => array('GET'),
'duration'=>3600,
'varyByParam' => array('Post_page'),
'dependency'=>array(
'class'=>'system.caching.dependencies.CDbCacheDependency',
'sql'=>'SELECT GREATEST(MAX(created), MAX(modified)) FROM post',
),
),
);
}
However this controller has several actions and I want to have a cache for a few others. But the dependency for each cache will vary. For example I have a view action to view a single post with comments. However the dependency for this should be "has either this specific post or comments changed?" rather than "has any post changed?" as above.
How can I specify a different cache dependency for each controller action? Additionally, is there an easier way to go about this caching without specifying bespoke caching strategies for each page?