Yii has good support for various server-side caching techniques and, since Version 1.1.11, it includes HTTP caching support that greatly affects website performance.
The idea is to tell clients that content wasn't changed using HTTP headers before actually sending it. This can save some time required to actually transfer the content. Another pro is that typically search engine robots are respecting HTTP headers and therefore will index your new pages faster since there is no need to process ones that weren't changed.
In this recipe, we will implement HTTP caching for the Gii-generated CRUD application aimed to store books.
First of all, create a fresh Yii application using
yiic webapp
.Create a database and adjust the
db
section of theprotected/config/main.php
configuration file to use it.Execute the following SQL:
CREATE TABLE book ( id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255) NOT NULL, text TEXT NOT NULL, created_at INT(11) NOT NULL, ...