Home > Article > PHP Framework > How to clear cache in thinkphp5.0
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.
#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;
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'); }
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!