Skip to content

QuellingBlade/web-cached-persistence

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

web-cached-persistence

Tools for cookie and local storage cache.

Why?

In some scenerio, we need to read local storage or cookie repeatedly. Sometimes, it is not necessary and a waste of system resource. This lib help to use Cookie and local storage with cache.

install and import

npm install web-cached-persistence
yarn add web-cached-persistence


import { CachedCookie, CachedStorage } from 'web-cached-persistence'

CachedStorage

const CachedTest = new CachedStorage('test') // create a cached local storage whose key is 'test'
CachedTest.set('123') // set local storage 'test' value to '123'.
CachedTest.get() // return '123'
CachedTest.remove() // remove the local storage record

CachedCookie

const CachedToken = new CachedCookie('token') // create a cached cookie
CachedToken.get() // return the cookie value and cache it
CachedToken.clear() // make the cookie calue to ''
CachedToken.renew() // refresh the cache and read value from cache, then return the new value.