Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist cache #46

Open
DrDreave opened this issue Jun 17, 2020 · 1 comment
Open

Persist cache #46

DrDreave opened this issue Jun 17, 2020 · 1 comment

Comments

@DrDreave
Copy link

Are there any plans on adding the option to persist the cached data?

I want to keep the cached data within a browser session (including page reloads). I thought about combining this plugin with vuex-persistedstate to get the expected behaviour. Unfortunately I found out that the cache data is not stored in the module's state, so it doesn't work as expected.

Are there any plans on making this plugin compatible with other plugins by offering an interface to load an initial state, ..? Or even better implementing a persistence option in this plugin?

Thanks in advance.

@VitorLuizC
Copy link
Collaborator

VitorLuizC commented Jun 17, 2020

I didn't have that plan. And persisting the memoization state seems strange to me, but receiving the state object in the options can solve this problem.

I'll add an option to change cache (state object).

createVuexCache({
  cache: {
    get: (key) => {
      const value = localStorage.getItem(key);
      if (value) return JSON.parse(value);
      return null;
    },
    has: (key) => localStorage.getItem(key) !== null,
    set: (key, value) => localStorage.setItem(key, JSON.stringify(value)),
    clear: localStorage.clear,
    delete: localStorage.removeItem,
  },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants