Skip to main content

QNamespacedCache

@quik/cache


@quik/cache / QNamespacedCache

Class: QNamespacedCache

Defined in: cache/src/QNamespacedCache.ts:16

Wraps an IQCache instance and prepends a fixed namespace prefix to every key.

Use this to partition a shared cache backend by concern without risking key collisions between modules.

Example

const usersCache = new QNamespacedCache(getCache(), 'users');
await usersCache.set('profile:1', data);
// stored as "users:profile:1" in the underlying cache

Implements

  • IQCache

Constructors

Constructor

new QNamespacedCache(_cache, _prefix): QNamespacedCache

Defined in: cache/src/QNamespacedCache.ts:17

Parameters

_cache

IQCache

_prefix

string

Returns

QNamespacedCache

Methods

clear()

clear(): Promise<void>

Defined in: cache/src/QNamespacedCache.ts:42

Remove all entries from the cache.

Returns

Promise<void>

Implementation of

IQCache.clear


delete()

delete(key): Promise<void>

Defined in: cache/src/QNamespacedCache.ts:34

Remove a value by key.

Parameters

key

string

Cache key.

Returns

Promise<void>

Implementation of

IQCache.delete


get()

get<T>(key): Promise<T>

Defined in: cache/src/QNamespacedCache.ts:26

Retrieve a value by key.

Type Parameters

T

T

Parameters

key

string

Cache key.

Returns

Promise<T>

Implementation of

IQCache.get


has()

has(key): Promise<boolean>

Defined in: cache/src/QNamespacedCache.ts:38

Check whether a key exists and has not expired.

Parameters

key

string

Cache key.

Returns

Promise<boolean>

Implementation of

IQCache.has


set()

set<T>(key, value, ttlMs?): Promise<void>

Defined in: cache/src/QNamespacedCache.ts:30

Store a value by key with an optional TTL.

Type Parameters

T

T

Parameters

key

string

Cache key.

value

T

Value to store.

ttlMs?

number

Optional time-to-live in milliseconds.

Returns

Promise<void>

Implementation of

IQCache.set