Location: PHPKode > scripts > Powerful Caching Script > example.php
<?php
/**
* http://codelikepandas.com for more coding tuts, snippets and help
* @author: Pablo Albrecht
* @date: 30 January 2011, 04:56 PM
*/

require_once 'CodeLikePandas_final.php';

/**

// Load the caching engine with a simple config array
$config = array(

	// !IMPORTANT: trailing slash's required
	'caching_path' => './cache/',
	
	// We want to cache only components that have a priority of 50 and above.
	'priority_required' => 50
);

*/

// Load the caching engine with the config file
$config = './configuration.php';

$cache = new CacheHandler($config);

// Let's do some tests

echo "Do we have a random value cached already ?";

// Try to retrieve the cache content with a priority of 75.
// Since we want to cache all the content with a priority higher or equal than 50 (as set in the $config array).
$content = $cache->retrieve_cache('random value',75);

if($content == false) {
	$random_value = mt_rand(0,100);
	echo " <strong>No!</strong>";
	echo "<br />Generating random value:";
	echo " Random value: " . $random_value;
	$cache->cache_content('random value',$random_value,10000);	
	echo "<br />Cache created!";	
}else { 
	echo "<br />Random value pulled from the cache engine (won't change if you reload the page) :<br /><strong>" . $content . "</strong>";
	echo "<br /><br />You can also delete the file in the cache folder to re-generate its content.";
}

/* End of file */
Return current item: Powerful Caching Script