Study cache_lite again

Source: Internet
Author: User
I studied cache_lite again and read details about cache_lite at night, which is much more powerful than I thought. Of course, I have not found whether it supports directly saving PHP code for caching, but I think it can be extended.

Here are several examples:

Require_once ('../Libs/cache/Lite. php');

$ Options= Array (
'Cachedir'=>'../Cache/test /',
'Filelocking'=>True,
'Writecontrol'=>True,
'Readcontrol'=>False,
'Filenameprotection'=>False,// Disable the file name security mode. The cache id and group name are directly applied to the name of the cache file, so be careful when using special characters.
'Icicserialization'=>False,// Disable automatic sequence
'Hasheddirectorylevel'=>2,// Set the two-level 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;
}
?>


Cache output

Require_once ('../Libs/cache/Lite. php');
Require_once (
'../Libs/cache/Lite/output. php');
$ Options= Array (
'Cachedir'=>'../Cache/test /',
'Lifetime'=>60,
'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();// The buffered output is now stored in a cache file.
}

?>


Cache functions

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 = new Cache_Lite_Function($options);

$cache->call('function_to_bench', 12, 45);

function
function_to_bench($arg1, $arg2)
{
echo
"This is the output of the function function_to_bench($arg1, $arg2) !
"
;
return
"This is the result of the function function_to_bench($arg1, $arg2) !
"
;
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.