superwf / vuex-cache

cache vuex action when dispatch
MIT License
510 stars 32 forks source link

TTL for cached items #6

Closed razekteixeira closed 6 years ago

razekteixeira commented 6 years ago

It could be a great feature to have some kind of configuration for all cache actions. We could pass to the cache.dispatch an options objeto which may have a ttl (seconds or something else) that will clear that cached item after some configurable time. This would avoid the delete of all cached items.

I'll try to do it and then I'll make a pill request as soon as I can.

Thanks for the plug-in ;)

VitorLuizC commented 6 years ago

That would be nice!

I was thinking if yours dispatch interceptor can conflict with other Vuex's plugins, but since we're using it though cache namespace we can change it's API without any problem.

We can use cache dispatch arguments with an object.

store.cache.dispatch({
  type: 'employee/fetchAll',
  payload: {
    company: this.company,
  },
  timeout: 1000 * 60 * 5, // 5 minutes.
});

Or just include an options after dispatch's payload.

store.cache.dispatch('employee/fetchAll', { company: this.company }, {
  timeout: 1000 * 60 * 5, // 5 minutes.
});

@superwf

superwf commented 6 years ago

add timeout feature, try it. :tada: