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.
【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,//禁止静态缓存
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['token']) ? trim($_GET['token']) : ''; $_operate = isset($_GET['operate']) ? trim($_GET['operate']) : ''; $_option = array(); if($_operate == 'runtime') $_option['temp'] = RUNTIME_PATH; //各种缓存数据存放目录 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'; } }
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!