How to write and update the cache function in thinkphp is to reload the webpage code by clicking the "update cache" button in the background (including the first and previous users) to reload the webpage code.
Reply to discussion (solution)
The simplest way is to delete all the caches and re-create them automatically when there is a visitor.
What are the first and previously accessed users?
So? Yes ?? ? Save it.
? Face? Save ??? Use? What is there ????
?? ? Yes? Set header ("cache-control: no-cache, must-revalidate.
Directly traverse the Runtime directory and delete it.
I agree to the upstairs, which is implemented using ajax.
Public function ajaxUpdateCache (){
If ($ this-> isPost ()){
If (file_exists (RUNTIME_FILE )){
Unlink (RUNTIME_FILE); // delete RUNTIME_FILE;
}
$ Cachedir = RUNTIME_PATH. "/Cache/"; // Cache file path;
If ($ dh = opendir ($ cachedir) {// open the Cache folder;
While ($ file = readdir ($ dh ))! = False) {// traverse the Cache Directory,
Unlink ($ cachedir. $ file); // delete each file that is traversed;
}
Closedir ($ dh );
}
$ Tempdir = RUNTIME_PATH. "/Temp/"; // Cache file path;
If ($ dh = opendir ($ tempdir) {// open the Cache folder;
While ($ file = readdir ($ dh ))! = False) {// traverse the Cache Directory,
Unlink ($ tempdir. $ file); // delete each file that is traversed;
}
Closedir ($ dh );
}
$ This-> ajaxReturn (array ("success" => true), 'json ');
} Else {
$ This-> ajaxReturn (array ("success" => false, "msg" => "Parameter error"), 'json ');
}
}
I don't know what your demand is
The browser has multiple caching mechanisms. you will know when page data is updated in the background.
If you want to click a button in the background and the browser will immediately refresh the page, you need to use ajax round-robin to check the number of seconds that the server needs to refresh.
What does this have to do with runtime? it has nothing to do with php's static page cache.