Home > Backend Development > PHP Problem > How to remove cache in php

How to remove cache in php

coldplay.xixi
Release: 2023-03-05 09:38:01
Original
3344 people have browsed it

php method to remove cache: 1. Add relevant code to the project configuration file [config.php]; 2. Delete the relevant folders of the cache directory of the TP framework; 3. In the same directory as the business controller Create your own [Clear Cache] class and clear the cache through URL access.

How to remove cache in php

Related learning recommendations: php graphic tutorial

How to remove cache in php:

First: Add the following two lines of code to the project configuration file config.php to avoid caching problems

  'TMPL_CACHE_ON' => false,//禁止模板编译缓存  
  'HTML_CACHE_ON' => false,//禁止静态缓存
Copy after login

This I won’t explain the two lines of code here;

Second: The cache directory of the TP framework is stored in the folder public_html\App\Runtime, and all files in it are manually deleted after each development is completed

Third: I wrote my own clear cache class. We can create our own "clear cache" class in the same directory as the business controller (the core idea is to use the cache class that comes with the TP framework to operate. The TP framework's You can take a look at the source code), and clear the cache through url access. The code is as follows:

// +----------------------------------------------------------------------
// | Copyright (c) 2007-2009 
// +----------------------------------------------------------------------
// $Id: ClearAction.class.php 668 2016-05-03 11:43:12Z chenhaibo $
/**
 +------------------------------------------------------------------------------
 * 清除缓存
 +------------------------------------------------------------------------------
 * @author    haibo <chenhaibo0806@163.com>
 * @version   $Id: ClearAction.class.php 668 2016-05-03 11:43:12Z chenhaibo $
 +------------------------------------------------------------------------------
 */
class ClearAction extends Action{
/**
+----------------------------------------------------------
* 清除缓存
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @return void
+----------------------------------------------------------
*/
public function clearcache() {
   $_token = isset($_GET[&#39;token&#39;]) ? trim($_GET[&#39;token&#39;]) : &#39;&#39;;
   $_operate = isset($_GET[&#39;operate&#39;]) ? trim($_GET[&#39;operate&#39;]) : &#39;&#39;;
 
   $_option = array();
   if($_operate == &#39;runtime&#39;) $_option[&#39;temp&#39;] = RUNTIME_PATH;  //各种缓存数据存放目录
   if($_operate == &#39;cache&#39;) $_option[&#39;temp&#39;] = CACHE_PATH;
   if($_operate == &#39;data&#39;) $_option[&#39;temp&#39;] = DATA_PATH;
   if($_operate == &#39;fields&#39;) $_option[&#39;temp&#39;] = DATA_PATH."/_fields";
 
   import(&#39;Think.Util.Cache.CacheFile&#39;);
   $CacheFile = new CacheFile($_option);
   $CacheFile->clear();
   echo &#39;success&#39;;
    }
}
Copy after login

If you want to know more about related learning, please pay attention to the php training column!

The above is the detailed content of How to remove cache in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template