@toshihiko/base-cache
v2.0.0-alpha.0
Published
Promise-only typed cache foundation for Toshihiko v2.
Readme
Toshihiko Base Cache
The Promise-only, typed foundation for Toshihiko v2 cache implementations.
Installation
npm install @toshihiko/base-cache toshihikoNode.js 22 or newer is required.
Implementing a Cache
Extend Cache and implement the four Toshihiko cache operations. The base class supplies the event emitter behavior used by the Redis and Memcached implementations, but does not impose key generation, batching, or option handling.
import {
Cache,
type CacheKey,
} from '@toshihiko/base-cache';
interface UserRow {
id: number;
name: string;
}
class MemoryCache extends Cache {
async getData<Value extends object>(
database: string,
table: string,
keys: CacheKey | readonly CacheKey[],
): Promise<Value[]> {
return [];
}
async setData<Value extends object>(
database: string,
table: string,
key: CacheKey,
data: Value,
): Promise<void> {}
async deleteData(
database: string,
table: string,
key: CacheKey,
): Promise<void> {}
async deleteKeys(
database: string,
table: string,
keys: readonly CacheKey[],
): Promise<void> {}
}License
MIT
