Something went wrong. Try again.
Something went wrong. Try again.
1.1 kB · 48 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import {SQLiteCache} from 'sqlite-cache';import {Type} from '@sinclair/typebox';
const DB_NAME = './cache.db'const LOGGING_ENABLED = false;
type Identity = { handle: string;}
type AccountMetadata = { did: string; displayName: string; handle: string; avatarCid: string | null;}
// Define your data schemaconst IdentitySchema = Type.Object({ handle: Type.String(),})
const AccountMetadataSchema = Type.Object({ did: Type.String(), displayName: Type.String(), handle: Type.String(), avatarCid: Type.Union([Type.String(), Type.Null()]),})
const identityCache = new SQLiteCache<string, Identity>({ path: DB_NAME, schema: IdentitySchema, ttl: 60_000 * 60, // 1 hour max: 1000, // Maximum 1000 entries log: LOGGING_ENABLED // Enable logging})
const accountMetadataCache = new SQLiteCache<string, AccountMetadata>({ path: DB_NAME, schema: AccountMetadataSchema, ttl: 60_000 * 10, // 1 hour max: 1000, // Maximum 1000 entries log: LOGGING_ENABLED // Enable logging})
export { identityCache, accountMetadataCache };export type { AccountMetadata };export default identityCache;