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

How to modify ThinkPHP cache to Memcache_PHP tutorial

WBOY
Release: 2016-07-13 10:26:12
Original
895 people have browsed it

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', 
Copy after login

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 行. 
Copy after login

So I found this sentence:

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

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',
Copy after login

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(); 
Copy after login

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...
Related labels:
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