Caching is the best way to improve the performances of your PHP application.
The cache method save all the output created by the draw method into a file, this file can be loaded directly faster, without executing all the necessary operation to design the dynamic template, as query and any php operation.
Since the cache save all the output, you should be carefully of how you use it, and for how long you maintain valid your cache.
You can configure the expiration time of a cache, and with the cache_id, you can save the same template with different contents.
Example:
<?php
//include RainTPL
include 'inc/rain.tpl.class.php';
//initialize
$tpl = new RainTPL();
// if there's a valid cache the method will return it
if( $cache = $tpl->cache( 'test', $expire_time = 600, $cache_id=null ) )
echo $cache;
else{
... query, operation, assign ....
//draw template...
$tpl->draw( 'test' );
}
?>
//include RainTPL
include 'inc/rain.tpl.class.php';
//initialize
$tpl = new RainTPL();
// if there's a valid cache the method will return it
if( $cache = $tpl->cache( 'test', $expire_time = 600, $cache_id=null ) )
echo $cache;
else{
... query, operation, assign ....
//draw template...
$tpl->draw( 'test' );
}
?>
Note:
You can clean the cache with this simple one line script:
array_map( "unlink", glob( raintpl::$cache_dir . "*.rtpl.php" ) );
it's possible to cache the same template with different contents, by settings a different $cache_id
