cache

handle storing data to localStorage

How to use

import { Plugin } from '@root'

Plugin.cache({
    ...CACHE_PAYLOAD
})

Cache payload

Save data to localStorage

import { Plugin } from '@root'

const item = {
    id: 'item-id',
    name: 'item name'
}

const onSave = () => {

}

Plugin.cache({
    key: 'my-cache-key',
    data: item,
    method: 'POST',
    callback: onSave
})

Get data from localStorage

import { Plugin } from '@root'

const onGet = cachedData => {
    console.log(cachedData)
    /*
        Output:
        {
            id: 'item-id',
            name: 'item name'
        }
    */
}

Plugin.cache({
    key: 'my-cache-key',
    method: 'GET', // can be ignored, as GET is the default method for cache
    callback: onGet
})

Remove data from localStorage

import { Plugin } from '@root'

Plugin.cache({
    key: 'my-cache-key',
    method: 'DELETE'
})

Last updated