Permalink
Browse files

limit client store item cache to 3 minutes

  • Loading branch information...
1 parent 0e2b0a1 commit ade06c60c0c3db9b5df16be7765667d88b23a1be @yyx990803 yyx990803 committed Dec 29, 2016
Showing with 13 additions and 0 deletions.
  1. +13 −0 src/store/index.js
View
@@ -36,6 +36,19 @@ const store = new Vuex.Store({
},
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) {
return fetchItems(ids).then(items => commit('SET_ITEMS', { items }))
} else {

0 comments on commit ade06c6

Please sign in to comment.