加缓存注意的坑
2016-03-11 15:24
597 查看
通过参数作为key值的坑
/** 通过用户id、城市编码、经纬度 来获取列表 获取规则: 1、如果有经纬度,通过经纬度获取列表 2、没有经纬度,如果有城市编码,通过城市编码获取列表 3、如果都没有,通过uid获取列表 */ function getIds($uid, $city_code=0, $lon=0, $lat=0, $is_cache = false, $page = 1, $count = -1 ){ if( empty($uid) || !is_numeric($uid) || $uid == 0 ) { Debug::setErrorMessage("uid不能为空"); return false; } if ( $city_code === 0 ) { if( intval($lon) === 0 && intval($lat) === 0 ) { $info = getInfoByUid($uid); } else { $info = getInfoByLatLon($lat,$lon); } $city_code = $info['city_code']; } if($city_code === 0 ) { $city_code = 110100; } $ids = array(); if( empty($city_code) || $city_code == 0 ) { $city_code = 110100; } $args = func_get_args(); array_shift($args); $key = md5( serialize($args)); //$key = md5( $city_code.serialize($args)); $key = "xxxx".$key; if( true === $is_cache ) { $result = ControllCache::getCache($key); if ( false !== $result ) { return $result; } } $ids = getIdsByCityCode($city_code); ControllCache::setCache($ids, 60, $key); return $ids; }
这个bug最不容易发现的地方在:当用户只传uid的时候,不同的用户通过uid获取的城市列表会不一样,但是除了uid之后,传的参数一样,结果会导致当前用户中的缓存时,是别的uid存进去的数据,导致获取城市列表不正确。
测试与线上的坑
测试机上测试时,不能将数据放入缓存,这样会影响线上获取线上的数据做版本控制时,需要将版本控制也融入到key值进行缓存,否则会影响线上服务
相关文章推荐
- 一个关于if else容易迷惑的问题
- SourceProvider.getJniDirectories
- PHP5.2.*防止Hash冲突拒绝服务攻击的Patch
- 深入理解PHP之匿名函数
- JSP/PHP基于Ajax的分页功能实现
- 关于PHP通过PDO用中文条件查询MySQL的问题。
- 什么是设计模式
- Trac 中文语言安装
- PHP数据库长连接mysql_pconnect的细节
- 软件 bug 的生命周期
- Php Installing An Expansion
- Mootools 1.2教程 函数
- autoit InputBox 函数
- Firefox2中输入框丢失光标bug的解决方法
- 文件遍历排序函数
- Oracle 函数大全[字符串函数,数学函数,日期函数]第1/4页
- ASP下经常用的字符串等函数参考资料
- PostgreSQL教程(五):函数和操作符详解(1)
- DOS批处理 函数定义与用法