Skip to Content
ComponentsCache (cache)

Cache (cache)

The cache component provides developers with high-level cache abstractions.

Data is stored in a hybrid memory and disk, where the disk can be mounted to either persistent or ephemeral storage (e.g. ramfs, ephemeral cloud SSDs); allowing for large cache sizes.

Setting cache values (cache.set)

Storing a value in the cache requires setting a key (string), a value (byte array), and the wanted time-to-live (TTL) for the value before it’s expired.

Example setting a cache value:

import { Diom } from "diom"; import { Temporal } from "temporal-polyfill-lite"; const client = new Diom("AUTH_TOKEN"); await client.cache.set( "my-cache-key", new TextEncoder().encode("cached value"), { ttl: Temporal.Duration.from({ seconds: 10 }) }, );

Getting cache values (cache.get)

Returns None when a value is not found.

const out = await client.cache.get("my-key", {}); if (out.value) { console.log("Got:", new TextDecoder().decode(out.value)); } else { console.log("Key not found"); }

Expiring cache values (cache.delete)

To expire a cache value (delete the key), call the cache.delete operation with the wanted key:

await client.cache.delete("my-key", {});
Last updated on