您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

ThinkPHP框架中使用Memcached缓存数据的方法

2024/3/6 9:12:13发布20次查看
这篇文章主要介绍了thinkphp框架中使用memcached缓存数据的方法,分析了thinkphp框架中memcached缓存的设置与使用相关操作技巧,需要的朋友可以参考下
本文实例讲述了thinkphp框架中使用memcached缓存数据的方法。分享给大家供大家参考,具体如下:
thinkphp默认使用文件缓存数据,支持memcache等其他缓存方式,有两个php扩展:memcache和memcached,memcahe官方有说明,主要说一下memcached。
相对于php memcache,php memcached是基于原生的c的libmemcached的扩展,更加完善,建议替换为php memcached。
版本3.2.2开始内置了memcached驱动(thinkphp/library/think/cache/driver/memcached.class.php),但是文档中并没有说明用法,通过查看源码配置并测试成功。
有个bug至今未修复,就是过期时间为0的问题,理论上应该是永久缓存,但是驱动中未做处理,会马上过期,set方法修改如下
public function set($name, $value, $expire = null) { n('cache_write',1); if(is_null($expire)) { $expire = $this->options['expire']; } $name = $this->options['prefix'].$name; if (empty($expire)) $time = 0; else $time = time() + $expire; if($this->handler->set($name, $value, $time)) { if($this->options['length']>0) { // 记录缓存队列 $this->queue($name); } return true; } return false; }
在配置文件config.php中添加
//缓存配置 'data_cache_type' => 'memcached', 'memcached_server' => array( array('127.0.0.1', 11211, 0) ),
驱动中是调用:
memcached::addservers(array)
可以添加多个缓存服务器
还有一个配置项是 memcached_lib,调用的是:
memcached::setoptions(array)
具体选项可参考php中文手册
相关推荐:
thinkphp框架中对表单的验证和ajax验证详解
以上就是thinkphp框架中使用memcached缓存数据的方法的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product