@arcjet/cache
弧喷 缓存接口和执行.
这是什么?
这是帮助我们缓存一些记忆的内部工具.
我什么时候用这个?
这是内部的Arcjet包件,不为公众使用而设计. 看我们的 开始吧 指南 如何使用Arcjet 在您的 应用.
安装
这套方案只是无害环境管理. 在 Node.js 用 npm 安装 :
npm install @arcjet/cache
使用
import { setTimeout } from "node:timers/promises";
import { MemoryCache } from "@arcjet/cache";
const cache = new MemoryCache<string>();
cache.set("namespace", "key", "value", 2);
console.log(await cache.get("namespace", "key"));
// => [ 'value', 2 ]
await setTimeout(2001);
console.log(await cache.get("namespace", "key"));
// => [ undefined, 0 ]
API 密码
MemoryCache#constructor()
说明 MemoryCache 使用 new MemoryCache() 没有任何争论.
MemoryCache#get(namespace: string, key: string): Promise<[T | undefined, number]>
试图从缓存取出一个值 。 如果存在一个值,它将是 与剩余时间(秒)一起返回.
非弦辩会让返回的承诺被拒绝.
MemoryCache#set(namespace: string, key: string, value: T, ttl: number): void
尽量将所提供值存储到有效时间 页:1.
非字符串参数会导致函数抛出.