Arcjet cache interface and implementations
npm install @arcjet/cache@arcjet/cache[Arcjet][arcjet] cache interface and implementations.
- npm package (@arcjet/cache)
- GitHub source code (cache/ in arcjet/arcjet-js)
This is an internal utility to help us cache some things in memory.
This is an internal Arcjet package not designed for public use.
See our [_Get started_ guide][arcjet-get-started] for how to use Arcjet in your
application.
This package is ESM only.
Install with npm in Node.js:
``sh`
npm install @arcjet/cache
`ts
import { setTimeout } from "node:timers/promises";
import { MemoryCache } from "@arcjet/cache";
const cache = new MemoryCache
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 ]
`
Instantiate the MemoryCache using new MemoryCache()` without any arguments.
Attempts to retrieve a value from the cache. If a value exists, it will be
returned with the remaining time-to-live (in seconds).
Non-string arguments will cause the returned promise to reject.
Makes a best attempt at storing the value provided until the time-to-live
specified.
Non-string arguments will cause the function to throw.
[Apache License, Version 2.0][apache-license] © [Arcjet Labs, Inc.][arcjet]
[arcjet]: https://arcjet.com
[arcjet-get-started]: https://docs.arcjet.com/get-started
[apache-license]: http://www.apache.org/licenses/LICENSE-2.0