Using cache dependencies and chains
Yii supports many cache backends, but what really makes Yii cache flexible is the dependency chaining support. There are situations when you cannot just simply cache data for an hour because the information cached can be changed at any time.
In this recipe, we will see how to cache a whole page and still always get fresh data when it is updated. The page will be dashboard type and will show the five latest articles added and a total calculated for an account. Note that an operation cannot be edited as it was added, but an article can.
Getting ready
Install APC (http://www.php.net/manual/en/apc.installation.php).
Generate a fresh Yii application by using
yiic webapp.Set up a cache in the
componentssection ofprotected/config/main.phpas follows:'cache' => array( 'class' => 'CApcCache', ),
Set up and configure a fresh database.
Execute the following SQL:
CREATE TABLE `account` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT,`amount` decimal(10,2) NOT NULL...