Modify ThinkPHP cache to Memcache _ php instance

Source: Internet
Author: User
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(); 

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.