Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
semour
/
semour_web
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9ffe949b
authored
Nov 10, 2022
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
一次性返回所有国家数据并且缓存
parent
6fba8feb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
4 deletions
.idea/workspace.xml
app/Http/Controllers/Api/CountryApiController.php
app/Http/Services/CountryService.php
.idea/workspace.xml
View file @
9ffe949b
...
...
@@ -2,9 +2,11 @@
<project
version=
"4"
>
<component
name=
"ChangeListManager"
>
<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/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/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"
/>
...
...
@@ -186,7 +188,7 @@
<workItem
from=
"1666835076791"
duration=
"693000"
/>
<workItem
from=
"1667266026118"
duration=
"40321000"
/>
<workItem
from=
"1667959054458"
duration=
"183000"
/>
<workItem
from=
"1667986756173"
duration=
"
6308
000"
/>
<workItem
from=
"1667986756173"
duration=
"
7143
000"
/>
</task>
<servers
/>
</component>
...
...
app/Http/Controllers/Api/CountryApiController.php
View file @
9ffe949b
...
...
@@ -16,6 +16,6 @@ class CountryApiController extends Controller
public
function
list
(
Request
$request
)
{
$data
=
CountryService
::
getCountryList
();
return
$this
->
setSuccessData
(
$data
[
'data'
],
$data
[
'total'
]
);
return
$this
->
setSuccessData
(
$data
);
}
}
app/Http/Services/CountryService.php
View file @
9ffe949b
...
...
@@ -3,12 +3,19 @@
namespace
App\Http\Services
;
use
App\Models\CountryModel
;
use
Illuminate\Support\Facades\Redis
;
class
CountryService
{
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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment