A simple, persistent cache for dead-simple apps.
$ yarn add altoque
# or npm i altoque
import Cache from 'altoque'
// or const Cache = require('altoque')
// Cache(<Boolean saveFile>, <String filename>)
// e.g const cache = Cache()
// or const cache = require('altoque')()
const cache = Cache(true, './cache.json')
cache.set('hello', 'there')
cache.get('hello') // there
cache.del('hello')
cache.get('hello') // undefined
cache.set('๐', '๐', 2) // save for 2 seconds
cache.get('๐', true) // { val: ๐, expires: 1535065557820 }
setTimeout(() => cache.get('๐'), 1000) // ๐
setTimeout(() => cache.get('๐'), 1000) // undefined
Note: All methods are synchronous.
Returns an object: { val: <value>, expires: <ms> }
.
- key: string
- value: string | any serializable object
Returns the entry value.
When showExpire
is true, it returns an object: { val: <value>, expires: <ms> }
.
- key: string
- showExpire: boolean
- key: string
$ yarn test
MIT