current position:Home>Thinkphp5 clear the cache cache, temp cache and log cache under runtime

Thinkphp5 clear the cache cache, temp cache and log cache under runtime

2022-06-24 09:45:23BigChen_ up

Mainly used php Function has :
array_map ( callback , array1 ,array… )
array_map -- Apply the fallback function for each element of the array
Parameters 1: Fallback function , Apply to every element in every array
Parameters 2: Array , Convenient operating parameters 1 Set function
Returns an array of , After including the fallback function processing array1 All elements of .

glob(pattern,flags)
glob — Find the file path that matches the pattern
Parameters 1: must . Specify search mode .
Parameters 2: Optional . Specify special settings . There is no more introduction here, because there is no .

If you want to achieve the effect, you can directly copy the following code :

<?php
namespace app\admin\controller;

use think\Cache;

class CacheController {
    

    //  Clear cache without deleting cache 
    public function clearCache() {
    
       Cache::clear();
       $this->success(" Clear successfully ");
    }
    
    //  Clear the template cache without deleting temp Catalog ;
	public function clearTemp() {
    
		array_map('unlink',glob(TEMP_PATH.'*.php'));
		$this->success(' Clear successfully ');
	}
	
	//  Clear log cache and delete log Empty directory 
	public function clearLog() {
    
		$path = glob(LOG_PATH . '*');
		foreach ($path as $val) {
    
			array_map('unlink', glob($val . DS . '*.log'));
			rmdir($val);
		}
		$this->success(' Clear successfully ');
	}
}

copyright notice
author[BigChen_ up],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/175/202206240807401772.html

Random recommended