Summary of several methods of PHP clear cache

Source: Internet
Author: User
This article mainly introduces the PHP clear cache of several methods to summarize the relevant information, hope that through this article you can master the method of clearing the cache, the need for friends can refer to the next

Summary of several methods of PHP clear cache

Now the development of the project is using tp3.1 version, in the development process we often encounter the problem of page cache (especially the HTML cache), after the refresh or the old version of the number, and then refresh the old version of the data, slowly began to doubt life, haha; so in the development process we need to clear the cache every time.

There are about 3 ways to clear the cache (both are actual experience summaries):

First: You can avoid caching problems by adding the following two lines of code to the project's configuration file config.php

' tmpl_cache_on ' + false,//prohibit template compilation cache  ' html_cache_on ' = false,//disable static caching

These two lines of code here I do not explain;

Second: The TP framework cache directory is stored in the folder Public_html\app\runtime, after each development is completed manually delete all the files inside
(feeling a bit violent and stupid), but this method is the stupidest, testing and online environment if you do not have permission to delete;

Third: I write to clear the cache class, we can in the business controller in the same directory to create their own "clear cache" class (the core idea is to use the TP framework with the cache class to operate, TP framework of the source code you can see), through the way of URL access to clear cache,

The code is as follows:

// +----------------------------------------------------------------------// | Copyright (c) 2007-2009//+----------------------------------------------------------------------//$Id: ClearAction.class.php 668 2016-05-03 11:43:12z Chenhaibo $/** +----------------------------------------------------- -------------------------* Clear Cache +------------------------------------------------------------------------------* @ Author Haibo <chenhaibo0806@163.com> * @version $Id: ClearAction.class.php 668 2016-05-03 11:43:12z Chenhaibo $ +--- ---------------------------------------------------------------------------*/class Clearaction extends action{/** +----------------------------------------------------------* Clear Cache +---------------------------------------------- ------------* @access public+----------------------------------------------------------* @return void+------------ ----------------------------------------------*/public function ClearCache () {$_token = Isset ($_get[' token '])? Trim ( $_get[' token ']): '; $_operate = isset ($_get[' operate ')?  Trim ($_get[' operate '): "; $_option = Array (); if ($_operate = = ' runtime ') $_option[' temp '] = Runtime_path; Various cache data holds directory if ($_operate = = ' cache ') $_option[' temp ' = Cache_path; if ($_operate = = ' data ') $_option[' temp '] = Data_path; if ($_operate = = ' Fields ') $_option[' temp '] = Data_path. "  /_fields "; Import (' Think.Util.Cache.CacheFile '); $CacheFile = new Cachefile ($_option); $CacheFile->clear (); echo ' success '; }

The clear function is actually deleting the cache file.


Browser address bar input address:

Http://test.xxx.cn/Clear-clearcache?operate=fields//test environment
Http://www.xxx.cn/Clear-clearcache?operate=fields//Formal environment

If you have any questions, please leave a message or talk to the community, thank you for reading, hope to help everyone.

Related Article

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.