Skip to content

Commit ade06c6

Browse files
committed
limit client store item cache to 3 minutes
1 parent 0e2b0a1 commit ade06c6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/store/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ const store = new Vuex.Store({
3636
},
3737

3838
FETCH_ITEMS: ({ commit, state }, { ids }) => {
39+
// on the client, the store itself serves as a cache.
40+
// only fetch items that we do not already have, or has expired (3 minutes)
41+
const now = Date.now()
42+
ids = ids.filter(id => {
43+
const item = state.items[id]
44+
if (!item) {
45+
return true
46+
}
47+
if (now - item.__lastUpdated > 1000 * 60 * 3) {
48+
return true
49+
}
50+
return false
51+
})
3952
if (ids.length) {
4053
return fetchItems(ids).then(items => commit('SET_ITEMS', { items }))
4154
} else {

0 commit comments

Comments
 (0)