Thinkphp-php Tutorial

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.