1.0.0 • Published 5 years ago
@nioh/cache v1.0.0
Runtime-Cache
内存缓存 in-memory cache
how to use
const Cache = require('@poseidon/runtime-cache')
const runtimeCache = new Cache({
debug: false,
max: 100,
overcut: 10 // 溢出时,需要清除的缓存百分比
})
API
get(key) 获取
let cache = runtimeCache.get('aaa')
判断过期后的处理
// 在 controller 中使用
if (cache && cache.expired && !cache.fetching) {
cache.fetching = true
await apiService()
cache.fetching = false
}
set(key, value, duration) 设置
runtimeCache.set('aaa', {b:1,c:1}, 60)
注:过期时间单位为秒
remove(key) 移除
runtimeCache.remove('aaa')
clear 清除
runtimeCache.clear()
1.0.0
5 years ago