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 style="COLOR: #000000"><code><span style="COLOR: #000000"><br><span style="COLOR: #0000bb"><? <BR></SPAN><SPAN style="COLOR: #007700">require_once(</SPAN><SPAN style="COLOR: #dd0000">'../libs/cache/Lite.php'</SPAN><SPAN style="COLOR: #007700">); <br><br></SPAN><SPAN style="COLOR: #0000bb">$id</SPAN><SPAN style="COLOR: #007700">=</SPAN><SPAN style="COLOR: #dd0000">'1'</SPAN><SPAN style="COLOR: #007700">; <BR></SPAN><SPAN style="COLOR: #0000bb">$options </SPAN><SPAN style="COLOR: #007700">= array( <BR> </SPAN><SPAN style="COLOR: #dd0000">'cacheDir' </SPAN><SPAN style="COLOR: #007700">=> </span><span style="COLOR: #dd0000">'../cache/test/'</span><span style="COLOR: #007700">, <br> </span><span style="COLOR: #dd0000">'lifeTime' </span><span style="COLOR: #007700">=> </span><span style="COLOR: #0000bb">60 <br></span><span style="COLOR: #007700">); <br></span><span style="COLOR: #0000bb">$cache</span><span style="COLOR: #007700">=new </span><span style="COLOR: #0000bb">Cache_Lite</span><span style="COLOR: #007700">(</span><span style="COLOR: #0000bb">$options</span><span style="COLOR: #007700">); <br>if(</span><span style="COLOR: #0000bb">$data</span><span style="COLOR: #007700">=</span><span style="COLOR: #0000bb">$cache</span><span style="COLOR: #007700">-></span><span style="COLOR: #0000bb">get</span><span style="COLOR: #007700">(</span><span style="COLOR: #0000bb">$id</span><span style="COLOR: #007700">)){ <br> echo </span><span style="COLOR: #0000bb">$data</span><span style="COLOR: #007700">; <br>}else{ <br> </span><span style="COLOR: #0000bb">$data</span><span style="COLOR: #007700">=</span><span style="COLOR: #0000bb">time</span><span style="COLOR: #007700">(); <br> </span><span style="COLOR: #0000bb">$cache</span><span style="COLOR: #007700">-></span><span style="COLOR: #0000bb">save</span><span style="COLOR: #007700">(</span><span style="COLOR: #0000bb">$data</span><span style="COLOR: #007700">); <br> echo </span><span style="COLOR: #0000bb">$data</span><span style="COLOR: #007700">; <br>} <br></span><span style="COLOR: #0000bb">?> <br></span></span>