Location: PHPKode > scripts > Cache output and objects > cache-output-and-objects/test_01_hello_world.php


$cache is object used to cache output and objects.

Cache constructor arguments are:

    - Location where cache files will be stored
    - Disable caching (for debugning purpuoses etc.)
    - Disable output of cached data
    - Data can still be accessed using $cache->output variable


$path = ".";
$file = "cache.test_01.tmp";
$expire = 20;

$cache = new Cache($path);

// Part in side of while loop is cached to $file

	echo("<b>Hello World!</b><br>");
	echo("In cached part it's ".date("H:i:s")."<br>");
	echo("<i>This part will expire in ".$expire." s</i><br>");
	echo("Output is stored in <b>".$path."/".$file."</b><br>");

echo("<b>This part is executed every time</b><br>");
echo("Real time is ".date("H:i:s")."<br>");

Return current item: Cache output and objects