1.1.3 • Published 5 years ago

wx-cache-interface v1.1.3

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

将微信wx适配为通用cache

install 安装

$ npm install wx-cache-interface

usage 使用

import {createLevelCache} from 'wx-cache-interface'

let wxCache = createLevelCache(window.wx)

// 储存了1
wxCache.save('a', 1)
// 此处save时设置了ttl
// 仅在储存方有自动触发删除操作时才有效,所以此处无任何作用
wxCache.save('a', 1, 60)


wxCache.load('a', 10) // 10秒以内都认为缓存命中
wxCache.load('a') // 默认ttl为1天

let foo = (a) => a
// 相当于调用foo(1),将结果缓存10秒
wxCache.applyWith('foo', foo, 10, [1])
// 把applyWith包装成一个新方法, 效果同上
let new_foo = wxCache.wrapperWithCall('foo', foo, 10)

通用cache的接口

interface ICache {
  save: (key: string, value: TValue, ttl?: number) => Promise<IValueWrapper<TValue>>,
  load: (key: string, ttl?: number) => Promise<TValue | undefined>,
  applyWith: (name: string, func: Function, ttl: number, params: any[]) => Promise<TValue>;
  wrapperWithCall: (name: string, func: Function, ttl: number) => (...params: any[]) => Promise<TValue>;
  timeDivider: () => number;
}
1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago