Heim >Backend-Entwicklung >PHP-Tutorial >cache_lite试用_PHP教程
今天研究下pear的cache_lite。
从http://pear.php.net上下载了最新的cache_lite。cache_lite是pear库类中一个轻型的cache库类。的确轻型,代码总计4个文件。lite.php cache/File.php cache/unction.php cache/output.php。而且扩展性特别好,加入到自己的库类,主要修改下lite.php的raiseError函数。
加入自己的库类后,开始测试。首先基本的缓存:
<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>