首頁  >  文章  >  php框架  >  thinkphp5.0 怎麼清除緩存

thinkphp5.0 怎麼清除緩存

藏色散人
藏色散人原創
2022-12-07 09:30:422309瀏覽

thinkphp5.0清除快取的方法:1、透過「public function clear_sys_cache(){...}」方法清除模版快取;2、透過「public function clear_log_chache(){...}」方法清除日誌快取並刪出log空目錄即可。

thinkphp5.0 怎麼清除緩存

本教學操作環境:Windows7系統、thinkphp5.0版、Dell G3電腦。

thinkphp5.0 怎麼清除快取?

thinkphp5.0清除快取、範本快取和日誌快取的方法 

直接寫入cache模組中,產生控制器

namespace app\cache\controller;
use think\Controller;
use think\Cache;

具體方法如下:

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');
}

推薦學習:《thinkPHP影片教學

以上是thinkphp5.0 怎麼清除緩存的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn