通过参数作为key值的坑
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 = "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值进行缓存,否则会影响线上服务