PHP Pear :: Cache_Lite Implementation Page Cocaine According to official documentation, this cache efficiency is very high, "Pear :: Cache_Lite Has to Be Extreme Fast", how is it? I didn't look carefully, I don't know if there is a suspect for Wang Po selling melon.
Pear :: Cache List Features: 1.simplicity2.security
Let's start a simple caching example, let everyone have a direct understanding. PHP Require_once ('cache / lite.pp'); // Set the path to the cache file to be stored and the effect of the cache (second), make sure this directory is written, $ Option = array ('Caching' => True, // defaults to true 'cachedir' => 'd: / tmp /', 'Lifetime' => 60); $ cache = new cache_lite ($ OPTION); // Partition domain cache IF ($ data = $ cache -> GET ('block1')) {Echo ($ data);} else {$ data = 'get block 1 Contents from anywhere
); $ cache-> save ($ data);} echo (' no Cache text
); if ($ data = $ cache-> get ('block2')) {echo ($ data);} else {$ data = 'get block 2 Contents from anywhere
$ Cache-> save ($ data);}?> Cache_lite does not guarantee that the cache page is always re-acquired, so it is recommended to use cache_lite_output, it will output directly, no need to manually call echo to rewrite the above example with cache_lite_output: PHP Require_once ('cache / lite / output.php'); $ option = array ('cachedir' => 'D: / tmp /', 'lifetime' => 60); $ cache = new cache_lite_output ($ Option); $ cache-> remove ('bocck1'); // Clear the previous a block IF (! ($ cache-> start ('block1'))) {Echo ('Block 1 Contents
); $ Cache-> end ();} echo ('NO C Ache text
'); if (! ($ cache-> start (' block2 '))) {Echo (' Block 2 Contents
); $ cache-> end ();} $ cache -> Clean (); // Clear cache?>
In order to ensure the maximum efficiency of Cache_Lite, do not include other files when the output cache is output, only the other files are included when there is no need to cache (recalculate). For example: incorrect method: Php request_once ("cache / Lite.php "); Require_once (" ... ") // contains other files required_once (" ... ") // (...) $ cache = new cache_lite (); if ($ data = $ Cache_lite-> get ($ ID)) {// cache hit! Echo ($ data);} else {// page Has to be (re) constructed in $ data // (...) $ cache_lite-> save $ DATA);}?>
Correct use:
php require_once ("cache / lite.php"); // (...) $ cache = new cache_lite (); if ($ data = $ cache_lite-> Get ($ ID)) {// cache hit! Echo ($ data);} else {// page Has to be (re) CONSTRUCTED IN $ data // Recalculate, contains other files Require_once ("...") Require_once ("...") // (...) $ cache_lite-> save ($ data);}?>