npm install @uam/vuejs-cache
yarn add @uam/vuejs-cache
This package need following packages installed in your app
- pouchdb-browser@^6.4.3
- vue@^2.5.16
- vuex@^3.0.1
Your api needs to attach a custom header for db version, the cache data is updated based on this version.
Install Vuejs cache plugin as follows:
# main.js
import cachePlugin from '@uam/vuejs-cache'
Vue.use(cachePlugin, {options})
Option | Description | Type | Required |
---|---|---|---|
store | Main store to which the cache module is attached to | Object | true |
axios | The instance of axios used by app | Object | true |
dbVersionHeaderKey | Custom response header key for db version | String | true |
cacheRoute | Route to fetch cache data | String | true |
Once you have registered the plugin. It attaches a uam_cache
module to the store, The cached data received from the cacheRoute can be accessed as
store.uam_cache.cache.<key>
Or
store.uam_cache.cache[<key>]
# File.vue
// ..
// ..
this.$store.getters['uam_cache/cacheData'](key)
The cache module has a getter updatingCache
that is true when the data is being fetched from the server.
you can use the getter to add visual clues about ongoing update.