Caching with PEAR::Cache - Combined Code
(Page 5 of 6 )
Based on the points illustrated in this tutorial, a possible framework for a cached script could resemble the following:
<?php include "Cache.php";
$store_as = "file"; $options = array("cache_dir" => getcwd() . "/cache");
$cache = new cache($store_as, $options); $cached_id = $cache->generateID($_SERVER["PHP_SELF"]);
if ($content = $cache->get($cached_id)) echo $content; else { ob_start(); // ...PHP script which results in output goes here. $content = ob_get_contents(); ob_end_clean(); $cache->save($cached_id, $content, 3600); echo $contents; } ?> |
Next: Conclusion >>
More PEAR Articles Articles
More By bluephoenix