Home > PHP Framework > ThinkPHP > thinkphp5 clear cache, template cache and log cache

thinkphp5 clear cache, template cache and log cache

藏色散人
Release: 2020-08-11 13:43:12
forward
3984 people have browsed it

The following tutorial column of thinkphp framework will introduce to you how to clear the cache, template cache and log cache of thinkphp5. I hope it will be helpful to friends in need!

thinkphp5 clear cache, template cache and log cache

Write directly into the cache module to generate the controller

namespace app\cache\controller;
use think\Controller;
use think\Cache;
Copy after login

The specific method is as follows:

public function Index()
{
return $this->fetch();
}
//清除模版缓存不删除cache目录;
public function clear_sys_cache()
{
Cache::clear();
$this->success('清除成功', 'Index/index');
}
//清除模版缓存但不删除temp目录;
public function clear_temp_ahce()
{
$path = glob(TEMP_PATH . '*.php');
array_map('unlink', $path);
$this->success('清除成功', 'Index/index');
}
//清除日志缓存并删出log空目录;
public function clear_log_chache()
{
$path = glob(LOG_PATH . '*');
foreach ($path as $item) {
//dump(glob($item .DS. '*.log'));
array_map('unlink', glob($item . DS . '*.log'));
rmdir($item);
}
$this->success('清除成功', 'Index/index');
}
Copy after login

The main php functions used are:

  • array_map ( callback , array1 , array... )

array_map --Apply callback to each element of the array Drop function

Parameter 1: Drop function, applied to each element in each array

Parameter 2: Array, convenient for running the function set by parameter 1

Return Array, containing all elements of array1 after processing by the callback function.

  • glob(pattern,flags)

##glob — Find file paths matching pattern

Parameter 1: required. Specifies the search mode.

Parameter 2: Optional. Specifies special settings. I won’t go into too much detail here because it won’t be used here.

The above is the detailed content of thinkphp5 clear cache, template cache and log cache. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template