local-caching
v2.0.0
Published
A programmatic data caching wrapper for browsers, based on localStorage.
Downloads
4
Readme
local-caching
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)
| Option | Type | Default | Description |
| --- | --- | --- | --- |
| storeKeyPrefix
| string | 'cache::'
| Key prefix for cache items. |
| storeMetaKeyPrefix
| string | 'cachemeta::'
| Key prefix for cache meta items. |