Commit 9ffe949b by 杨树贤

一次性返回所有国家数据并且缓存

parent 6fba8feb
...@@ -2,9 +2,11 @@ ...@@ -2,9 +2,11 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="fb90add0-1393-48c2-9f26-72365d42cd03" name="变更" comment=""> <list default="true" id="fb90add0-1393-48c2-9f26-72365d42cd03" name="变更" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Controllers/Api/CountryApiController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/Api/CountryApiController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Services/CountryService.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Services/CountryService.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/bootstrap/app.php" beforeDir="false" afterPath="$PROJECT_DIR$/bootstrap/app.php" afterDir="false" /> <change beforePath="$PROJECT_DIR$/bootstrap/app.php" beforeDir="false" afterPath="$PROJECT_DIR$/bootstrap/app.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/bootstrap/cache/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/bootstrap/cache/.gitignore" afterDir="false" /> <change beforePath="$PROJECT_DIR$/bootstrap/cache/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/bootstrap/cache/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/routes/api.php" beforeDir="false" afterPath="$PROJECT_DIR$/routes/api.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/storage/app/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/app/.gitignore" afterDir="false" /> <change beforePath="$PROJECT_DIR$/storage/app/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/app/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/storage/app/public/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/app/public/.gitignore" afterDir="false" /> <change beforePath="$PROJECT_DIR$/storage/app/public/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/app/public/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/storage/framework/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/framework/.gitignore" afterDir="false" /> <change beforePath="$PROJECT_DIR$/storage/framework/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/framework/.gitignore" afterDir="false" />
...@@ -186,7 +188,7 @@ ...@@ -186,7 +188,7 @@
<workItem from="1666835076791" duration="693000" /> <workItem from="1666835076791" duration="693000" />
<workItem from="1667266026118" duration="40321000" /> <workItem from="1667266026118" duration="40321000" />
<workItem from="1667959054458" duration="183000" /> <workItem from="1667959054458" duration="183000" />
<workItem from="1667986756173" duration="6308000" /> <workItem from="1667986756173" duration="7143000" />
</task> </task>
<servers /> <servers />
</component> </component>
......
...@@ -16,6 +16,6 @@ class CountryApiController extends Controller ...@@ -16,6 +16,6 @@ class CountryApiController extends Controller
public function list(Request $request) public function list(Request $request)
{ {
$data = CountryService::getCountryList(); $data = CountryService::getCountryList();
return $this->setSuccessData($data['data'], $data['total']); return $this->setSuccessData($data);
} }
} }
...@@ -3,12 +3,19 @@ ...@@ -3,12 +3,19 @@
namespace App\Http\Services; namespace App\Http\Services;
use App\Models\CountryModel; use App\Models\CountryModel;
use Illuminate\Support\Facades\Redis;
class CountryService class CountryService
{ {
public static function getCountryList() public static function getCountryList()
{ {
$result = CountryModel::paginate(10)->toArray(); $countryListCache = Redis::get('sem_country_list');
if ($countryListCache) {
return json_decode($countryListCache, true);
}
$result = CountryModel::select(['id', 'name'])->get()->toArray();
Redis::set('sem_country_list', json_encode($result));
Redis::expire('sem_country_list', 3600);
return $result; return $result;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment