(1) The default caching method for thinkphp is file mode, and a lot of cache files are generated under/runtime/temp.
Server installed memcached and want to change into Memecache way
Add in conf/config.php
' Data_cache_type ' = ' Memcache ',
' Memcache_host ' = ' tcp://127.0.0.1:11211 ',
' Data_cache_time ' = ' 3600 ',
(2) thinkphp official download extension thinkphp_extend_3.1.2/extend/driver/cache/cachememcache.class.php save to Thinkphp/lib/driver/cache /cachememcache.class.php
(3) Test: S (' Test ', ' memcache '); $test = s (' Test '); echo $test;//output memcache test succeeded.
(4) memcached use test:
$test = S (' test '); if (! $test { $test = ' cache information '; S (' test ',$test, +); Echo $test. ' -From the database ';} Else { echo$test. ' -From memcached ';}
Attached: s function code
/** * Cache management * @param mixed $name cache name, if the array represents cache settings * @param mixed $value Cached values * @param mixed $options Cache parameters * @return Mixe D*/functionS$name,$value= ",$options=NULL) { Static $cache= ' '; if(Is_array($options) &&Empty($cache)){ //simultaneous initialization of cache operations $type=isset($options[' type '])?$options[' type ']: '; $cache= Cache::getinstance ($type,$options); }ElseIf(Is_array($name)) {//Cache Initialization $type=isset($name[' type '])?$name[' type ']: '; $cache= Cache::getinstance ($type,$name); return $cache; }ElseIf(Empty($cache)) {//Automatic Initialization $cache= Cache::getinstance (); } if(' = = =$value){//Get Cache return $cache->get ($name); }ElseIf(Is_null($value)) {//Delete Cache return $cache->RM ($name); }Else{//Cache Data if(Is_array($options)) { $expire=isset($options[' expire '])?$options[' Expire ']:NULL; }Else{ $expire=Is_numeric($options)?$options:NULL; } return $cache->set ($name,$value,$expire); }}
thinkphp using Memcache cache server