Home >Backend Development >PHP Tutorial >How to modify ThinkPHP cache to Memcache_PHP tutorial

How to modify ThinkPHP cache to Memcache_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:26:12893browse

Generally speaking, ThinkPHP's default caching method is implemented in File file mode, and many cache files will be generated under /Runtime/Temp during runtime.
In some cases, after memcached is installed on the server, it is necessary to change ThinkPHP's caching method to memecache
The specific steps are as follows:

Add in Conf/config.php:

'DATA_CACHE_TYPE' => 'Memcache', 
'MEMCACHE_HOST'  => 'tcp://127.0.0.1:11211', 

After updating the cache, I refreshed the page and found that the cache did not take effect.
Get debugging information:

[ 2010-09-30T11:41:56+08:00 ] NOTIC: [8] MemcachePool::set(): Server 127.0.0.1 (tcp 11211, udp 0) failed with: CLIENT_ERROR bad command line format (0) CacheMemcache.class.php 第 107 行. 

So I found this sentence:

return $this->handler->set($name, $value, 0, $expire); 

After further debugging, it was found that the value of $expire is -1; the cache duration was not specified when writing the program, and the -1 here may not be accepted by memcached.
So add in Conf/config.php:

'DATA_CACHE_TIME' => '3600',

Specify the default cache duration as 3600 seconds; run it again, the error disappears, and the cache is successful!

In addition, when you need to clear all caches in a certain action, you can do this:

$cache = Cache::getInstance(); 
$cache ->clear(); 

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824795.htmlTechArticleGenerally speaking, ThinkPHP’s default caching method is implemented in File file mode, and it will be in /Runtime/ during runtime. Many cache files are generated under Temp. In some cases, the server has memcached installed...
Statement:
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