PHP Classes
Icontem

File: partial_caching.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jesus M. Castagnetto  >  Generalized CachedTemplate class  >  partial_caching.php  
File: partial_caching.php
Role: ???
Content type: text/plain
Description: Example of using get_from_cache to implement partial caching
Class: Generalized CachedTemplate class
General Template Caching class
 

Contents

Class file image Download
<?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 = "&amp;#".$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";

?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products