Skip to content

Commit 4a0f69d

Browse files
committed
fix(repo): 优化缓存操作
1 parent 9d97aea commit 4a0f69d

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

laravel/app/Http/Repository/BusRepository.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,12 @@ public function getListV2($line, $refresh = false)
230230
if ($refresh) {
231231
Cache::forget('line_name:'.$line);
232232
}
233-
return Cache::remember('line_name:'.$line, 3600 * 24 * 30, function() use ($line) {
233+
234+
$return = Cache::get('line_name:'.$line);
235+
if ($return) {
236+
return $return;
237+
}
238+
try {
234239
// 新版本直接调用接口
235240
$url = 'http://www.szjt.gov.cn/BusQu/APTSLine.aspx/GetData';
236241
$param = '{"num":"'.$line.'"}';
@@ -252,13 +257,13 @@ public function getListV2($line, $refresh = false)
252257
if ($arr['Document']) {
253258
foreach ($arr['Document']['LineInfo'] as $item) {
254259
// "Guid": "921f91ad-757e-49d6-86ae-8e5f205117be",
255-
// "LName": "快线1号",
256-
// "LDirection": "星塘公交中心首末站",
257-
// "LFStdFTime": "06:00:00",
258-
// "LFStdETime": "21:00:00",
259-
// "LFStdName": "木渎公交换乘枢纽站",
260-
// "LEStdName": "星塘公交中心",
261-
// "LineType": ""
260+
// "LName": "快线1号",
261+
// "LDirection": "星塘公交中心首末站",
262+
// "LFStdFTime": "06:00:00",
263+
// "LFStdETime": "21:00:00",
264+
// "LFStdName": "木渎公交换乘枢纽站",
265+
// "LEStdName": "星塘公交中心",
266+
// "LineType": ""
262267
$fromTo = $item['LDirection'] ?? '';
263268
$bus = $item['LName'] ?? '';
264269
$Guid = $item['Guid'] ?? '';
@@ -272,10 +277,17 @@ public function getListV2($line, $refresh = false)
272277
'line_type' => $item['LineType'] ?? '',
273278
];
274279
}
280+
cache(['line_name:'.$line => $return], 3600 * 24 * 30);
275281
return $return;
276282
}
277283
}
278284
}
285+
} catch (\Exception $e) {
286+
return [];
287+
}
288+
return Cache::remember('line_name:'.$line, 3600 * 24 * 30, function() use ($line) {
289+
290+
return [];
279291
});
280292
}
281293

0 commit comments

Comments
 (0)