This article mainly introduces how to modify ThinkPHP cache to Memcache. For more information, see. Generally, the default caching method of ThinkPHP is implemented by using File files, during Runtime, many cached files are generated under/Runtime/Temp.
In some cases, after memcached is installed on the server, you need to change the ThinkPHP cache mode to memecache mode.
The procedure is as follows:
Add in Conf/config. php:
'DATA_CACHE_TYPE' => 'Memcache', 'MEMCACHE_HOST' => 'tcp://127.0.0.1:11211',
After the cache is updated, the page is refreshed and the cache does not take effect.
Obtain the debugging information:
[2010-09-30T11: 41: 56 + 08: 00] NOTIC: [8] MemcachePool: set (): Server 127.0.0.1 (tcp 11211, udp 0) failed: CLIENT_ERROR bad command line format (0) CacheMemcache. class. php 107th rows.
So I found this sentence:
return $this->handler->set($name, $value, 0, $expire);
After further debugging, we found that the value of $ expire is-1. The cache duration is not specified during program writing. Here,-1 may not be accepted by memcached.
Add the following in Conf/config. php:
'DATA_CACHE_TIME' => '3600',
Specify the default cache duration of 3600 seconds. Run the command again. The error is missing and the cache is successful!
In addition, you can clear all the caches in an action as follows:
$cache = Cache::getInstance(); $cache ->clear();