首先要开启扩展功能Memcached 端口:11211 ThinkPHP封装的缓存类:CacheMemcache $Cache = Cache::getInstance('memcache'); //或者: $options = array('host' => '127.0.0.1', 'port' => 11211, 'timeout' => 10, 'persistent' => false); $Cache = Cache::getInstance('memcache', $options); $Cache->set('name','ThinkPHP'); // 缓存name数据 $value = $Cache->get('name'); // 获取缓存的name数据 echo $value;
原始类:Memcache $mem = new Memcache; $mem->connect('127.0.0.1', 11211); $val = $mem->get('key'); if($val == 'test') { echo '缓存'; }else{ $mem->set('key', 'test', 0, 60); echo '写入'; } |
|