Summary of several methods for clearing cache in PHP and several methods for caching in php

Source: Internet
Author: User

Summary of several methods for clearing cache in PHP and several methods for caching in php

Summary of several methods for clearing cache in PHP

Currently, the development project uses tp3.1. during the development process, we often encounter page cache problems (especially the html cache). After refreshing, it is still the old version number, refresh the old version of data and slowly start to doubt your life. Haha; so we need to clear the cache every time during the development process.

There are about three methods to clear the cache (which are summarized in actual experiences ):

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

'Tmpl _ CACHE_ON '=> false, // disable template compilation cache 'html _ CACHE_ON' => false, // disable static Cache

I will not explain these two lines of code here;

Second, the cache directory of the TP framework is stored in the public_html \ App \ Runtime folder, and all files in the folder are manually deleted after each development.
(It seems a bit violent and stupid), but this method is the dumbest. The test and online environments cannot be deleted if they have no permissions;

Third, I wrote the clear cache class myself, 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 for operations, you can refer to the source code of the TP framework). The cache can be clearly identified through url access,

The Code is as follows:

// + Response // | Copyright (c) 2007-2009 // + ---------------------------------------------------------------------- // $ Id: ClearAction. class. php 668 11: 43: 12Z chenhaibo $/** + cache * clear cache + ------------------------------------------------------------------ ------------ * @ Author haibo <chenhaibo0806@163.com> * @ version $ Id: ClearAction. class. php 668 11: 43: 12Z chenhaibo $ + handler */class ClearAction extends Action {/** + handler * clear cache + handler * @ access public + ------------- ------------------------------------------- * @ Return void + response */public function upload AchE () {$ _ 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 storage directories 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 used to delete cached files.


Enter the address in the address bar of the browser:

Http://test.xxx.cn/Clear-clearcache? Operate = fields // test environment
Http://www.xxx.cn/Clear-clearcache? Operate = fields // official environment

If you have any questions, please leave a message or go to the community on this site for discussion. Thank you for reading this article. Thank you for your support!

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.