browser-cache-store
v1.0.0
Published
A simple cache store that uses IndexedDB (falls back to localStorage if IndexedDB is not available).
Downloads
7
Readme
browser-cache-store
A simple cache store that uses IndexedDB (falls back to localStorage if IndexedDB is not available).
This library offers the following features:
- Every operation on the cache store is atomic.
- Users can retrieve the previous value associated with a key and replace it with a new value in a single atomic operation.
Installation:
npm i browser-cache-store
Examples:
import { createCacheStore } from 'browser-cache-store'
const store = createCacheStore('the_store_name')
// put value
store
.put('counter', (prev) => (prev || 0) + 1)
.then((res) => {
console.log(res.prev)
console.log(res.next)
})
// set value
store.set('key', 'value').then(() => {
console.log('set')
})
// get value
store.get('key').then((value) => {
console.log(value)
})
// remove key
store.remove('key').then(() => {
console.log('removed')
})
// remove all
store.clear().then(() => {
console.log('cleared')
})