Kill lui lei Dog---PHP Development App Interface---5 (Core technology caching technology)

Source: Internet
Author: User

Caching technology:

1. Static caching

Static files stored on disk, with PHP generated data into static files

2.Memcache and Redio Cache

The cache is primarily designed to reduce server stress.

PHP Operation Cache

1. Generating the cache

2. Get the cache

3. Delete Cache

<?PHPclass File{        Private $_dir; ConstEXT = '. txt ';  Public function__construct () {$this-_dir =dirname(__file__).‘ /files ';//the folder where the cache directory is stored by default        }         Public functionCacheData ($k,$v= ",$path= ' '){            $filename=$this->_dir.$path.$k. Self::EXT; if($v!== ') {//write $v value to cache                if(Is_null($v)){                    return@unlink($filename); }                $dir=dirname($filename); if(!Is_dir($dir)){//determine if a directory exists                    mkdir($dir, 0777);//does not exist then create the directory                }                                return file_put_contents($filename, Json_encode ($v)); }                        if(!Is_file($filename)){                return false; }Else{                returnJson_decode (file_get_contents($filename),true); }        }    }

The test code is as follows:

<?PHPinclude('./7.php '); //test the XML data    $data=Array(        ' id ' = 1, ' name ' = ' lisi ', ' type ' = =Array(1,7,89,Array(' 5 ', ' A ', ' d ', ' d '))    ); $file=New File(); //The $data here means that if the value exists, the cache is opened and the cache is generated if it does not exist .    if($fileCacheData (' Index_mk_cache '/*, $data*/,NULL)){        //Var_dump ($file->cachedata (' Index_mk_cache ')); exit;        Echo"Success"; }Else{        Echo"Error"; }

Kill lui lei Dog---PHP Development App Interface---5 (Core technology caching technology)

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.