Home >Backend Development >PHP Tutorial >cached failure cache_lite trial
Let’s study pear’s cache_lite today.
Downloaded the latest cache_lite from http://pear.php.net. cache_lite is a lightweight cache library class in the pear library class. It is indeed lightweight, with a total of 4 files of code. lite.php cache/File.php cache/unction.php cache/output.php. And the scalability is very good. Add it to your own library class and mainly modify the raiseError function of lite.php.
After adding your own library class, start testing. First basic caching:
<span><br><span><? <BR></SPAN><SPAN>require_once(</SPAN><SPAN>'../libs/cache/Lite.php'</SPAN><SPAN>); <br></SPAN><SPAN>$id</SPAN><SPAN>=</SPAN><SPAN>'1' </SPAN><SPAN>; <BR></SPAN><SPAN>$options </SPAN><SPAN>= array( <BR> </SPAN><SPAN>'cacheDir' </SPAN><SPAN>=> </span><span>'../cache/test/'</span><span>, <br> </span><span>' lifeTime' </span><span>=> </span> <span>60 <br></span><span>); <br></span><span>$cache</span><span>=new </span><span>Cache_Lite</span><span>(</span><span>$options</span><span>); <br>if(</span><span>$data</span><span>=</span> <span>$cache</span><span>-></span> <span>get</span><span>(</span><span>$id</span><span>)){ <br> echo </span><span>$data</span><span>; <br>}else{ <br> </span><span>$data</span><span>=</span><span>time</span><span>(); <br> </span><span>$cache</span><span> -></span><span>save</span><span>(</span><span>$data</span><span>); <br> echo </span><span>$data</span><span>; <br>} <br></span><span>?> <br></span></span>
The above introduces the cached failure cache_lite trial, including cached failure. I hope it will be helpful to friends who are interested in PHP tutorials.