The evening detailed look at the next cache_lite, the function than I imagined more powerful. Of course I have not yet found out whether it supports the ability to directly save PHP code to cache, but I think it is possible to extend the implementation.
Here are a few examples:
require_once ('.. /libs/cache/lite.php ');
$options= Array (
' Cachedir '='.. /cache/test/',
' filelocking '=true,
' Writecontrol '=true,
' Readcontrol '=false,
' Filenameprotection '=false,//Close file name Safe mode. The cache ID and group name are applied directly to the file name of the cache file, so use special characters with caution.
' Automaticserialization '=false,//Turn off automatic sequences
' Hasheddirectorylevel '=2,//Set level two cache path
' LifeTime '=60
);
$Cache= newCache_lite($options);
$id=' Test ';
if ($data=$Cache -Get($id,' Test ')){
Echo$data;
}else{
$data= Time();
$Cache -Save($data);
Echo$data;
}
?>
Caching the output
require_once ('.. /libs/cache/lite.php ');
Require_once ('.. /libs/cache/lite/output.php ');
$options= Array (
' Cachedir '='.. /cache/test/',
' LifeTime '= -,
' Pearerrormode '=Cache_lite_error_die
);
$cache=newCache_lite_output($options);
if (! ($cache -Start(' Id_of_the_page '))) {
//No cache found!
Echo' Test time: '. Time().'
Test
';
$cache -End(); //Buffered output is now stored in a cache file
}
?>
To cache a function
require_once ('.. /libs/cache/lite.php ');
Require_once ('.. /libs/cache/lite/function.php ');
$options= Array (
' Cachedir '='.. /cache/test/',
' LifeTime '=3600,
' Pearerrormode '=Cache_lite_error_die
);
$cache= newcache_lite_function($options);
$cache -Pager(' Function_to_bench ', A, $);
functionFunction_to_bench($arg 1, $arg 2)
{
Echo"This is the output of the function Function_to_bench ($arg 1, $arg 2)!
";
Return"This is the result of the function function_to_bench ($arg 1, $arg 2)!
";
}
?>
http://www.bkjia.com/PHPjc/317938.html www.bkjia.com true http://www.bkjia.com/PHPjc/317938.html techarticle The evening detailed look at the next cache_lite, the function than I imagined more powerful. Of course I haven't found out yet whether it supports the ability to save PHP code to cache directly, but I think it should be ...