Home > PHP Framework > ThinkPHP > How to clear cache in thinkphp5.0

How to clear cache in thinkphp5.0

藏色散人
Release: 2022-12-07 09:30:42
Original
2464 people have browsed it

Thinkphp5.0 method to clear the cache: 1. Clear the template cache through the "public function clear_sys_cache(){...}" method; 2. Through the "public function clear_log_chache(){...}" method Just clear the log cache and delete the empty log directory.

How to clear cache in thinkphp5.0

#The operating environment of this tutorial: Windows 7 system, thinkphp version 5.0, Dell G3 computer.

thinkphp5.0 How to clear cache?

thinkphp5.0 method of clearing the cache, template cache and log cache

Write directly into the cache module and 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

Recommended learning: "thinkPHP Video Tutorial"

The above is the detailed content of How to clear cache in thinkphp5.0. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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