PHP Pear :: Cache

xiaoxiao2021-03-06  40

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. 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: '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: get ($ ID)) {// cache hit! Echo ($ data);} else {// page Has to be (re) constructed in $ data // (...) $ cache_lite-> save $ DATA);}?>

Correct use:

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);}?>

转载请注明原文地址:https://www.9cbs.com/read-56962.html

New Post(0)