/locache

Simple utility function to get and set data in your localStorage

Primary LanguageJavaScript

locache

Simple utility function to get and set data in your localStorage, and sessionStorage

Install

npm install locache

Usage for localStorage cache

import { cache } from 'locache';

Set (save) items in localStorage

var tom = {
  name: 'Tom',
  age: '26',
  height: 'tall',
  weight: '74kg'
}

cache('profile').set(tom);

Get items from localStorage

var profile = cache('profile').get();

profile will now equal the following

{
  name: 'Tom',
  age: '26',
  height: 'tall',
  weight: '74kg'
}

Remove items in localStorage

cache('profile').remove();

Usage for sessionStorage cache

import { sessionCache } from 'locache';

Set (save) items in sessionStorage

var tom = {
  name: 'Tom',
  age: '26',
  height: 'tall',
  weight: '74kg'
}

sessionCache('profile').set(tom);

Get items from sessionStorage

var profile = sessionCache('profile').get();

profile will now equal the following

{
  name: 'Tom',
  age: '26',
  height: 'tall',
  weight: '74kg'
}

Remove items in sessionStorage

sessionCache('profile').remove();