Professional CodeIgniter, Thomas Myer
Chapter 9: Security and Performance
289
For example, if you were to set a 30 - minute cache in
welcome/index()
, you would do it like this:
function index(){
$this- 
> 
output- 
> 
cache(30); 
  $data[`title'] = "Welcome to Claudia's Kids";
  $data[`navlist'] = $this- 
> 
MCats- 
> 
getCategoriesNav();
  $data[`mainf'] = $this- 
> 
MProducts- 
> 
getMainFeature();
  $skip = $data[`mainf'][`id'];
  $data[`sidef'] = $this- 
> 
MProducts- 
> 
getRandomProducts(3,$skip);
  $data[`main'] = `home';
  $this- 
> 
load- 
> 
vars($data);
  $this- 
> 
load- 
> 
view(`template');
} 
If you were to reload the home page, you ' d notice a few things right away. First off, it ' s likely that this
first page load might take a bit longer. But there ' s no need to panic, as every subsequent visit will be
speedier than the last. The other thing you ' ll notice is that all your profiling data have been removed.
Again, there ' s no need to panic. Below, you ' ll learn how to use a more discreet way to display such data,
using benchmarking.
If you were to look at your server ' s file system, you ' d see that there are now files being written to the /
system/cache folder, as shown in Figure 9 - 2 .
Figure 9 - 2
c09.indd   289
c09.indd   289
6/10/08   5:38:05 PM
6/10/08   5:38:05 PM