Home >Backend Development >PHP Tutorial >thinkphp如何写更新缓存功能

thinkphp如何写更新缓存功能

WBOY
WBOYOriginal
2016-06-13 12:06:381592browse

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

Statement:
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