- Static cache (static files stored on disk, with PHP generated data into static files)
A) PHP operation cache
I. Generating a cache
II. Get the cache
Iii. Deleting a cache
Determine if the directory exists: Is_dir ()
DirName (__file__): You can get the current directory of the file
mkdir (): Create directory
Unlink (): Delete file
<?PHP//Static Cachingclass File{ Constext= ". txt"; Private $_dir; Public function__construct () {//Default Path $this->_dir=dirname(__file__).‘ /files/'; } /** * $key cache filename * $value Cache value * $path cache file Directory **/ Public functionCacheData ($key,$value= ",$path= ' '){ $filename=$this->_dir.$path.$key. Self::EXT; if($value!== ') {//write value values to cache if(Is_null($value)){//Delete a cache file return@unlink($filename); } $dir=dirname($filename); if(!Is_dir($dir)){ mkdir($dir, 0777);//Create a cache catalog file } return file_put_contents($filename, Json_encode ($value)); } //Get Cache if(!Is_file($filename)){ return false; }Else{ returnJson_encode (file_get_contents($filename),true); } }}$data=Array(' id ' =>1, ' name ' = ' ann ');//instantiating the file class $file=New File();//Generate Cache if($file->cachedata (' Index_cache ',$data)) { Echo' Success '; }Else{ Echo' Error '; } //Get Cache/*if ($file->cachedata ("Index_cache")) {Var_dump ($file->cachedata ("Index_cache")); }else{echo ' ERROR '; } */ //Delete Cache /*if ($file->cachedata (' Index_cache ', null)) {echo ' success '; } else{echo ' Errors '; }*/?>
2.Memcache Redis Cache
Setting up the cache
Failed to set cache after 15 seconds
To get the cached value:
PHP operation Memcache (see PHP Manual for more)
1. Installing the memcache Extension
2.L Connection Service-connect (' Memcache_host ', 11211);
3.set Set Cache
4. Get Cache
Timed tasks (Linux systems)
Timed Task commands
1. Scheduled Task Service provides crontab command to set the service
2.CRONTAB-E//Edit a user's cron service
3. Crontab-l//list details of a user cron service
4.crontab-r//Delete a user's cron service
PHP Cache Technology (reduces database server stress)