$paramArr['sorttype'] = getParam('sorttype', 1); $cachKey = md5(implode(',', $paramArr)); $nowTime = time(); $registrationList = ''; $isGetCache = false; //判断是否从session缓存中获取数据 if (isset($_SESSION[$cachKey])) { $cacheData = $_SESSION[$cachKey]; if ($nowTime - $cacheData['time'] <= 3 * 60) { $registrationList = $cacheData['data']; $isGetCache = true; } } //缓存过期获取无缓存时数据库读取数据 if (!$registrationList && !$isGetCache) { $registrationList = $registrationObj->getRegistrationList($paramArr); $cacheArr = array('key' => $cachKey, 'time' => $nowTime, 'data' => $registrationList); $_SESSION[$cachKey] = $cacheArr; } $resultJsonData = array(); if ($registrationList) { $resultJsonData = array('status' => 200, 'message' => 'success', 'list' => $registrationList['resultList'], 'nums' => $registrationList['rowNums']); } else { if ($registrationObj->errorMessage) { $resultJsonData = array('status' => 201, 'message' => $registrationObj->errorMessage, 'list' => '', 'nums' => 0); } else { $resultJsonData = array('status' => 202, 'message' => 'not data', 'list' => '', 'nums' => 0); } } //返回json格式数据。 echo json_encode($resultJsonData);