altoque
A dead-simple cache for simple apps
Last updated 2 years ago by mallendeo .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install altoque 
SYNC missed versions from official npm registry.

Al toque Build Status

A simple, persistent cache for dead-simple apps.

Install

$ yarn add altoque
# or npm i altoque

Usage

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 

API

Note: All methods are synchronous.

Cache.set(key, value)

Returns an object: { val: <value>, expires: <ms> }.

  • key: string
  • value: string | any serializable object

Cache.get(key, showExpire)

Returns the entry value.

When showExpire is true, it returns an object: { val: <value>, expires: <ms> }.

  • key: string
  • showExpire: boolean

Cache.del(key)

  • key: string

Test

$ yarn test

License

MIT

Current Tags

  • 1.0.4                                ...           latest (2 years ago)

1 Versions

  • 1.0.4                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |