<?php
/*
* $Id: partial_caching.php,v 1.1 2001/02/07 01:03:39 jesus Exp $
*/
// This test file is a simple modification of a
// sample file included in FastTemplate
// this example shows partial caching
require "./class.FastTemplate.php3";
require "./class.FastTemplateAdaptor.php";
require "./class.CachedTemplate.php";
$ftpl = new CachedTemplate();
$ftpl->init("./templates");
// for benchmarking
$start = $ftpl->utime();
// the templates are distributed w/FastTemplate
// we need this definition first, so the new logic can
// detect if the templates have changed.
$ftpl->define(
array(
main => "main.tpl",
table => "table.tpl",
row => "row.tpl"
)
);
// Check if we can send the cached table
if ($ftpl->valid_cache_file("mytable")) {
$table = "(<b>cached table</b>)<br>".$ftpl->get_from_cache("mytable");
} else { // otherwise, create the table and cache it
for ($n=250; $n < 256; $n++) {
$Number = "&#".$n."; = ";
$BigNum = chr($n);
$ftpl->assign(
array(
NUMBER => $Number,
BIG_NUMBER => $BigNum
)
);
$ftpl->parse(ROWS,".row");
}
$ftpl->parse(TABLE,"table");
$table = $ftpl->getParsedDoc(TABLE);
// write the table to a cahe file
$ftpl->write_to_cache($table,time(),"mytable");
}
// make the main body - uncached
$uncached = "Numeric entitities ".$table;
$uncached .= "<hr>Last edited on: ";
$uncached .= date("l, Y-m-d, H:i:s T",filemtime($PATH_TRANSLATED))."<br>";
$uncached .= "Last accessed on: ".date("l, Y-m-d, H:i:s T");
$doctitle = "FastTemplate Test - Partial caching ".date("l, Y-m-d, h:i:s");
$ftpl->assign( array(
TITLE => $title,
MAIN => $uncached
) );
$ftpl->parse(PAGE, "main");
// get parsed document
echo $ftpl->getParsedDoc(PAGE);
// for benchmarking
$end = $ftpl->utime();
$runtime = ($end - $start) * 1000;
echo "<br>Processing completed in $runtime miliseconds<BR>\n";
?>
|