Ksenia Subbotina
Ksenia Subbotina

Reputation: 81

Cache ttl of cache in Vue

i'm using Vuex and vuex-persistedstate in my project.
How can I change time to live(ttl) of local storage in Vue?
Sorry for my bad English P.S. i use this solution When do items in HTML5 local storage expire? .

Upvotes: 0

Views: 1465

Answers (1)

Stephan-v
Stephan-v

Reputation: 20369

vuex-persistedstate seems to be making use of this cookie library:

https://github.com/js-cookie/js-cookie#expires

This example has the expired property as well(taken from their documentatiion):

const store = new Store({
  // ...
  plugins: [
    createPersistedState({
      storage: {
        getItem: key => Cookies.get(key),
        setItem: (key, value) =>
          Cookies.set(key, value, { expires: 3, secure: true }),
        removeItem: key => Cookies.remove(key),
      },
    }),
  ],
})

The number 3 here is the number of days, if you want less you can follow this FAQ:

https://github.com/js-cookie/js-cookie/wiki/Frequently-Asked-Questions#how-to-make-the-cookie-expire-in-less-than-a-day

Upvotes: 1

Related Questions