1.3.0 • Published 6 years ago

wxapp-cache v1.3.0

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

wxapp-cache

A simple and reliable cache for wxapp client.

Features

  • L1 cache is in memory, for best performance
  • L2 cache is wxStorage, all changes in the memory cache will also be written into wxStorage on device

The keys in wxStorage have prefix 'wxapp-cache:'.

Usage

const cache = require('wxapp-cache')

cache.set('userInfo', {id: 1234, name: 'Kate'})
cache.set('token', 'secretString', 3600) // will expire in one hour

cache.get('not exist') // undefined
cache.get('userInfo') // Object {id: 1234, name: 'Kate'}
cache.get('token') // String secretString

setTimeout(function () {
  cache.get('token') // undefined, because expire
}, 3600 * 1000)

cache.remove('userInfo')
cache.get('userInfo') // undefined, because removed

cache.clear() // return a promise
  .then(keys => {
    console.log(keys) // ["token"]
  })
1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

7 years ago

1.0.0

7 years ago