1.0.2 • Published 4 years ago

@vencakrecl/vuex-simple-cache v1.0.2

Weekly downloads
124
License
MIT
Repository
github
Last release
4 years ago

vuex-simple-cache

NPM package version License Last test status

  • simple cache for vuex action

How to install

npm install @vencakrecl/vuex-simple-cache
yarn add @vencakrecl/vuex-simple-cache

How to use

import Vue from 'vue';
import Vuex, { Store } from 'vuex';
import VuexSimpleCache from '@vencakrecl/vuex-simple-cache';

Vue.use(Vuex);

const store = new Store({});

// create for every module
const cache = new VuexSimpleCache()

store.registerModule('test', {
  state: {
    items: [{ name: 'cachedData' }],
  },
  actions: {
    testAction: cache.cacheAction(
      'items',
      ({ commit }) => {
        // call API
        const data = [{ name: 'newData' }];

        return data;
      },
    ),
    testAction2: cache.cacheAction(
      'items',
      ({ commit }) => {
        // call API
        const data = [{ name: 'newData' }];

        commit('testMutation', data);

        return data;
      },
      120, // cache data for 120 seconds
      ({ commit }, data) => { // onCache callback
        commit('testMutation', data);
      }
    ),
  },
  mutation: {
    testMutation: (state, payload) => {
      state.items = payload
    }
  }
})

API - VuexSimpleCache.cacheAction

  • key - name of key from vuex state
  • action - standard vuex action
  • expiration - time in seconds (default 30s)
  • onCache - callback for cached data (default return cached data)
1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-beta.0

4 years ago

1.0.0-alpha.9

4 years ago

1.0.0-beta.1

4 years ago

1.0.0-alpha.7

5 years ago

1.0.0-alpha.8

5 years ago

1.0.0-alpha.6

5 years ago

1.0.0-alpha.5

5 years ago

1.0.0-alpha.3

5 years ago

1.0.0-alpha.2

5 years ago

1.0.0-alpha.1

5 years ago