Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sample
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
周韬
node-sample
Commits
ade06c60
Commit
ade06c60
authored
Dec 29, 2016
by
Evan You
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
limit client store item cache to 3 minutes
parent
0e2b0a16
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
0 deletions
+13
-0
index.js
src/store/index.js
+13
-0
No files found.
src/store/index.js
View file @
ade06c60
...
@@ -36,6 +36,19 @@ const store = new Vuex.Store({
...
@@ -36,6 +36,19 @@ const store = new Vuex.Store({
},
},
FETCH_ITEMS
:
({
commit
,
state
},
{
ids
})
=>
{
FETCH_ITEMS
:
({
commit
,
state
},
{
ids
})
=>
{
// on the client, the store itself serves as a cache.
// only fetch items that we do not already have, or has expired (3 minutes)
const
now
=
Date
.
now
()
ids
=
ids
.
filter
(
id
=>
{
const
item
=
state
.
items
[
id
]
if
(
!
item
)
{
return
true
}
if
(
now
-
item
.
__lastUpdated
>
1000
*
60
*
3
)
{
return
true
}
return
false
})
if
(
ids
.
length
)
{
if
(
ids
.
length
)
{
return
fetchItems
(
ids
).
then
(
items
=>
commit
(
'SET_ITEMS'
,
{
items
}))
return
fetchItems
(
ids
).
then
(
items
=>
commit
(
'SET_ITEMS'
,
{
items
}))
}
else
{
}
else
{
...
...
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