How to remove cache in php

coldplay.xixi
Release: 2023-03-05 09:38:01
Original
3204 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  * @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'; } }
Copy after login

If you want to know more about related learning, please pay attention to thephp trainingcolumn!

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!