🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@nioh/cache

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nioh/cache

cache with weight, in-memory

latest
npmnpm
Version
1.0.0
Version published
Weekly downloads
4
300%
Maintainers
1
Weekly downloads
 
Created
Source

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()

Keywords

cache

FAQs

Package last updated on 12 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts