Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial thinkphp怎么写更新缓存功能

thinkphp怎么写更新缓存功能

Jun 23, 2016 pm 01:49 PM
thinkphp Function renew cache

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


回复讨论(解决方案)

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

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

??器?存可以?置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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Windows cannot access the specified device, path, or file Windows cannot access the specified device, path, or file Jun 18, 2024 pm 04:49 PM

A friend's computer has such a fault. When opening "This PC" and the C drive file, it will prompt "Explorer.EXE Windows cannot access the specified device, path or file. You may not have the appropriate permissions to access the project." Including folders, files, This computer, Recycle Bin, etc., double-clicking will pop up such a window, and right-clicking to open it is normal. This is caused by a system update. If you also encounter this situation, the editor below will teach you how to solve it. 1. Open the registry editor Win+R and enter regedit, or right-click the start menu to run and enter regedit; 2. Locate the registry "Computer\HKEY_CLASSES_ROOT\PackagedCom\ClassInd"

Windows permanently pauses updates, Windows turns off automatic updates Windows permanently pauses updates, Windows turns off automatic updates Jun 18, 2024 pm 07:04 PM

Windows updates may cause some of the following problems: 1. Compatibility issues: Some applications, drivers, or hardware devices may be incompatible with new Windows updates, causing them to not work properly or crash. 2. Performance issues: Sometimes, Windows updates may cause the system to become slower or experience performance degradation. This may be due to new features or improvements requiring more resources to run. 3. System stability issues: Some users reported that after installing Windows updates, the system may experience unexpected crashes or blue screen errors. 4. Data loss: In rare cases, Windows updates may cause data loss or file corruption. This is why before making any important updates, back up your

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

How to install thinkphp How to install thinkphp Apr 09, 2024 pm 05:42 PM

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

How is the performance of thinkphp? How is the performance of thinkphp? Apr 09, 2024 pm 05:24 PM

ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.

See all articles