locache

2.0.1 • Public • Published

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();

Dependents (0)

Package Sidebar

Install

npm i locache

Weekly Downloads

0

Version

2.0.1

License

ISC

Unpacked Size

5.2 kB

Total Files

5

Last publish

Collaborators

  • tjcafferkey