Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
vuex-cache
Advanced tools
When vuex action fetch some data by request remote api, vuex-cache can store the action result, when next time the same action runs, it will not make a new request and just return the cached result.
update to use babel7 env to compile. If there is something wrong, please let me know by issue.
timeout
optionstore.cache.dispatch({
type: ACTION_NAME,
timeout: 100,
payload: { ... }
})
// or
store.cache.dispatch(ACTION_NAME, payload, {
timeout: 100,
})
after the timeout
time, run store.cache.dispatch(...)
will rerun the real dispatch code.
timeout
optionBecause the js execution also spends time, so the timeout
maybe not very accurate for computer time. For example
cache for 100 millisecond
store.cache.dispatch({
type: ACTION_NAME,
timeout: 100,
})
... after 99 millisecond
store.cache.dispatch({
type: ACTION_NAME,
timeout: 100,
})
In logic, the cache is not out of time, and the real dispatch should not run. But the cache.dispatch
may cost 1 or more milliseconds for executing, so the real dispatch may or may not execute.
For human time, the precision should be enough.
vuex-cache
just deals with Vuexnpm install vuex-cache
import Vuex from 'vuex'
import vuexCache from 'vuex-cache'
const store = new Vuex.Store({
state: {
...
},
plugins: [vuexCache],
mutations: {
...
},
actions: {
...
}
})
store.cache.dispatch('LIST')
From version 1.0.0 your env should has Map object, or import Map from babel-polyfill Thanks VitorLuizC
cacheDispatch will cache the result, so do not use it to make some actions with different params, when params change, cacheDispatch would still return the first cached result, and the data in store will not change.
From version 1.1.0 it could cache ACTION_NAME with or without params.
Thanks the idea by eele94
NOTICE: When with object param, the param will be converted to JSON for the cache key, so be careful the object key order. Object with different key order will transfer to different JSON string, and will generate independent cache.
JSON.stringify({a: 1, b: 2}) // '{"a":1,"b":2}'
JSON.stringify({b: 2, a: 1}) // '{"b":1,"a":2}'
With or without param, cacheDispatch will create independent cache. When with object param like
{
type: ACTION_NAME,
param: {...}
}
vuex-cache use JSON.stringify to generate the cache key, so the object do not must be the same object, just with same structure it will be dill with to the same cache.
store.cache.dispatch(ACTION_NAME)
// or
store.cache.dispatch(ACTION_NAME, param)
// or
store.cache.dispatch({
type: ACTION_NAME,
param: {...}
})
params is same with vuex store.dispatch
store.cache.delete(ACTION_NAME)
// or
store.cache.delete(ACTION_NAME, param)
// or
store.cache.delete({
type: ACTION_NAME,
param: {...}
})
remove cached action, will NOT remove the data in store. when call cacheDispatch with same type, the request in that action will run again.
store.cache.has(ACTION_NAME)
// or
store.cache.has(ACTION_NAME, param)
// or
store.cache.has({
type: ACTION_NAME,
param: {...}
})
return bool if ACTION_NAME has been cached
store.cache.clear()
clear all cached keys
FAQs
Cache dispatched actions and prevent repeated requests and heavy actions.
The npm package vuex-cache receives a total of 3,968 weekly downloads. As such, vuex-cache popularity was classified as popular.
We found that vuex-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.