2.0.0 • Published 2 years ago

local-caching v2.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
2 years ago

local-caching

Version Downloads License

A programmatic data caching wrapper for browsers, based on localStorage.

Installation

Node.js

$ npm install --save local-caching

Browser via CDN

<script src="https://cdn.jsdelivr.net/npm/local-caching/dist/index.umd.js"></script>

Usage

Instance

import LocalCaching from 'local-caching'

const localCaching = new LocalCaching()
localCaching.init()

Set cache data

localCaching.set('foo', 'bar', 300e3) // 5 minues
localCaching.set('numberValue', 12138, 300e3)
localCaching.set('booleanValue', true, 300e3)
localCaching.set('nullValue', null, 300e3)
localCaching.set('arrayValue', ['bar', 12138, null, true], 300e3)
localCaching.set('objectValue', { foo: 'bar' }, 300e3)

Get cache data

const foo          = localCaching.get('foo')
const numberValue  = localCaching.get('numberValue')
const booleanValue = localCaching.get('booleanValue')
const nullValue    = localCaching.get('nullValue')
const arrayValue   = localCaching.get('arrayValue')
const objectValue  = localCaching.get('objectValue')

Flush all items

localCaching.flushAll()

Flush only expired items

localCaching.flushExpired()

Constructor

new LocalCaching(options)
OptionTypeDefaultDescription
storeKeyPrefixstring'cache::'Key prefix for cache items.
storeMetaKeyPrefixstring'cachemeta::'Key prefix for cache meta items.

License

MIT