web-cached-persistence
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i web-cached-persistence

Weekly Downloads

5

Version

1.0.5

License

ISC

Unpacked Size

6.77 kB

Total Files

14

Last publish

Collaborators

  • njleonzhang