memcache在tp3.2中的使用
1、先看下服务是否开启来了,如何安装和开启memcached请看我前面一篇经验。

2、在web目录下新建phpinfo.php内容
<?php phpinfo();
然后在浏览器中输入localhost/phpinfo.php访问
查找下看是否已经安装好memcache扩展了。

3、在tp3.2的配置文件中config.php 添加
'DATA_CACHE_TIME' => 1800, // 数据缓存有效期s
'DATA_CACHE_TYPE' => 'Memcache', //数据缓存类型
'MEMCACHE_HOST' => 'tcp://127.0.0.1:11211',

4、memcache的实例化,设置内容和获取内容方式一
在IndexController的index方法中加入以下内容做个测试
//连接
$mem = new \Think\Cache\Driver\Memcache;
$mem->set('key1', 'This is first value', 0, 60);
$val = $mem->get('key1');
echo "Get key1 value: " . $val ."<br />";
$class = new \Think\Cache\Driver\Memcache();
$class->set('key','1234');
$data = $class->get('key');
echo $data;

5、memcache设置内容和获取内容方式二,调用S方法。
在IndexController的index方法中加入以下内容做个测试
S('test','hello memcache');
$mem_test = S('test');
echo $mem_test; //输出hello memcache表示成功

6、效果展示。
