当前位置:Gxlcms > PHP教程 > thinkphp如何写更新缓存功能

thinkphp如何写更新缓存功能

时间:2021-07-01 10:21:17 帮助过:30人阅读

thinkphp怎么写更新缓存功能
就是后台有个更新缓存的按钮 点击一下 所有用户(包括第一次访问的和 以前访问过的用户) 重新加载网页代码


------解决思路----------------------
public function ajaxUpdateCache() {
if ($this->isPost()) {
if (file_exists(RUNTIME_FILE)) {
unlink(RUNTIME_FILE); //删除RUNTIME_FILE;
}
$cachedir = RUNTIME_PATH . "/Cache/"; //Cache文件的路径;
if ($dh = opendir($cachedir)) { //打开Cache文件夹;
while (($file = readdir($dh)) !== false) { //遍历Cache目录,
unlink($cachedir . $file); //删除遍历到的每一个文件;
}
closedir($dh);
}
$tempdir = RUNTIME_PATH . "/Temp/"; //Cache文件的路径;
if ($dh = opendir($tempdir)) { //打开Cache文件夹;
while (($file = readdir($dh)) !== false) { //遍历Cache目录,
unlink($tempdir . $file); //删除遍历到的每一个文件;
}
closedir($dh);
}
$this->ajaxReturn(array("success" => true), 'JSON');
} else {
$this->ajaxReturn(array("success" => false, "msg" => "参数错误"), 'JSON');
}
}

人气教程排行