Skip to main content

QFileCache

@quik/cache


@quik/cache / QFileCache

Class: QFileCache

Defined in: cache/src/QFileCache.ts:25

File-system backed cache implementation.

Each entry is stored as a JSON file named after the SHA-256 hash of its key. Expired entries are evicted lazily on access. Requires no external dependencies.

Example

const cache = new QFileCache(".cache");
await cache.set("greeting", "hello", 60_000);
console.log(await cache.get("greeting")); // "hello"

Implements

  • IQCache

Constructors

Constructor

new QFileCache(folder): QFileCache

Defined in: cache/src/QFileCache.ts:28

Parameters

folder

string

Returns

QFileCache

Methods

clear()

clear(): Promise<void>

Defined in: cache/src/QFileCache.ts:108

Remove all cache files from the storage folder.

Returns

Promise<void>

Implementation of

IQCache.clear


delete()

delete(key): Promise<void>

Defined in: cache/src/QFileCache.ts:80

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/QFileCache.ts:50

Retrieve a value by key, returning undefined if missing or expired.

Type Parameters

T

T = unknown

Parameters

key

string

Cache key.

Returns

Promise<T>

Implementation of

IQCache.get


has()

has(key): Promise<boolean>

Defined in: cache/src/QFileCache.ts:93

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/QFileCache.ts:69

Store a value by key with an optional TTL.

Type Parameters

T

T = unknown

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