interface ICacheStore
Since 0.1.0

Key/value cache with per-entry TTL.

Examples

Example 1

const cache = ctx.services.get<ICacheStore>(CAPABILITIES.CACHE);
await cache.set('user:123', user, 3600);
const cached = await cache.get<User>('user:123');

Methods

get<T>(key: string): Promise<T | null>

Reads a cached value.

set<T>(
key: string,
value: T,
ttlSeconds?: number
): Promise<void>

Stores a value.

delete(key: string): Promise<boolean>

Removes a cached value.

has(key: string): Promise<boolean>

Reports whether a live entry exists.

clear(): Promise<void>

Removes every entry (respecting the store's key prefix, if configured).

Usage

import { type ICacheStore } from "cache-plugin/src/index.ts";