Cache API#

Storage#

Kind: global class

new Storage()#

Storage implementation

storage.driver โ‡’#

Get the name of the driver being used.

Kind: instance property of Storage
Returns:

Name of the driver

storage.ready() โ‡’#

Reflect the readiness of the store.

Kind: instance method of Storage
Returns:

Returns a promise that resolves when the store is ready

storage._getDriverOrder()#

Kind: instance method of Storage
Hidden:

storage.get(key) โ‡’#

Get the value associated with the given key.

Kind: instance method of Storage
Returns:

Returns a promise with the value of the given key

ParamDescription
key

the key to identify this value

storage.set(key, value) โ‡’#

Set the value for the given key.

Kind: instance method of Storage
Returns:

Returns a promise that resolves when the key and value are set

ParamDescription
key

the key to identify this value

value

the value for this key

storage.remove(key) โ‡’#

Remove any value associated with this key.

Kind: instance method of Storage
Returns:

Returns a promise that resolves when the value is removed

ParamDescription
key

the key to identify this value

storage.clear() โ‡’#

Clear the entire key value store. WARNING: HOT!

Kind: instance method of Storage
Returns:

Returns a promise that resolves when the store is cleared

storage.length() โ‡’#

Kind: instance method of Storage
Returns:

Returns a promise that resolves with the number of keys stored.

storage.keys() โ‡’#

Kind: instance method of Storage
Returns:

Returns a promise that resolves with the keys in the store.

storage.forEach(iteratorCallback) โ‡’#

Iterate through each key,value pair.

Kind: instance method of Storage
Returns:

Returns a promise that resolves when the iteration has finished.

ParamDescription
iteratorCallback

a callback of the form (value, key, iterationNumber)

getCache(key) โ‡’ *#

Get cache based on some key

Kind: global function

ParamType
key*

Example

import { getCache } from '@rebased/cache';
const dataKey = 'my-key';
console.log(await getCache('my-key'))

install(name, store, [driver])#

Cache setup

Kind: global function

ParamTypeDefault
name*
store*
[driver]string"['sqlite', 'indexeddb', 'localstorage']"

resetCache()#

Clear cache storage

Kind: global function

setCache(key, value) โ‡’ Void#

Programmatically way to set a key based cache

Kind: global function

ParamType
key*
value*

storage() โ‡’ StorageAdapter#

Retrieve the storage instance

Kind: global function

storageConfig([db], [store], [driver]) โ‡’ *#

Config helper

Kind: global function

ParamTypeDefault
[db]string"'app:db'"
[store]string"'app:store'"
[driver]string"['sqlite', 'indexeddb', 'localstorage']"