Re-study the underlying cache_lite_php

Source: Internet
Author: User
Evening in detail looked at the next cache_lite, the function is more powerful than I imagined. Of course I haven't found out yet whether it supports the ability to save PHP code directly to cache, but I think it should be extensible.

Here are a few examples:

?
Require_once ('.. /libs/cache/lite.php ');

$options= Array (
' Cachedir '=>'.. /cache/test/',
' Filelocking '=>True,
' Writecontrol '=>True,
' Readcontrol '=>False,
' Filenameprotection '=>False,Turn off file name Safe mode. Cache IDs and group names are applied directly to the file name of the cache file, so be careful with special characters.
' Automaticserialization '=>False,Turn off automatic sequence
' Hasheddirectorylevel '=>2,//Set level two cache path
' lifeTime ' => 60
);
$Cache = new cache_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   =new  cache_lite_output ( $options );

if  (!) ( $cache start ( ' id_of_the_page ' ))  { 
    &NBSP //  not found cache !
     echo  ' test time: ' . Time (). ' <br>test<br> ' ;
     $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   = new  cache_lite_function ( $options );

$cache call ( ' function_to_bench ' ,   ,  );

function  function_to_bench ( $arg 1 ,   $arg 2 )  
{
&NBSP;&NBSP;&NBSP;&NBSP;ECHO&NBSP this is the output of the function  function_to_bench ($arg 1,  $arg 2)  !<br> ";
    return  this is the result of the  Function function_to_bench ($arg 1,  $arg 2)  !<br> ";
}
?>

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.