Home  >  Article  >  Backend Development  >  thinkphp怎么写更新缓存功能

thinkphp怎么写更新缓存功能

WBOY
WBOYOriginal
2016-06-23 13:49:11961browse

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


回复讨论(解决方案)

最简单的办法就是删除全部缓存,有访客时自动重建

第一次访问的和 以前访问过的用户?
那?是??器?存吧。
?面?存???用?有什????

??器?存可以?置header("cache-control:no-cache,must-revalidate"); 实现。

直接遍历Runtime目录,删除即可。

同意楼上的,我用的ajax实现的

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

不知道你这个需求是为了什么
浏览器有多个缓存机制,你后台更新了页面数据,它会知道的
如果想后台点了按钮,前台正在浏览的用户立刻刷新,就需要用ajax轮询,每隔多少秒问一次服务器是否需要刷新

这个跟runtime有什么关系啊  跟php没关系 静态页面的缓存

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