A fork of pds-dash for selfhosted.social
1import {SQLiteCache} from 'sqlite-cache';
2import {Type} from '@sinclair/typebox';
3
4const DB_NAME = './cache.db'
5const LOGGING_ENABLED = false;
6
7type Identity = {
8 handle: string;
9}
10
11type AccountMetadata = {
12 did: string;
13 displayName: string;
14 handle: string;
15 avatarCid: string | null;
16}
17
18// Define your data schema
19const IdentitySchema = Type.Object({
20 handle: Type.String(),
21})
22
23const AccountMetadataSchema = Type.Object({
24 did: Type.String(),
25 displayName: Type.String(),
26 handle: Type.String(),
27 avatarCid: Type.Union([Type.String(), Type.Null()]),
28})
29
30const identityCache = new SQLiteCache<string, Identity>({
31 path: DB_NAME,
32 schema: IdentitySchema,
33 ttl: 60_000 * 60, // 1 hour
34 max: 1000, // Maximum 1000 entries
35 log: LOGGING_ENABLED // Enable logging
36})
37
38const accountMetadataCache = new SQLiteCache<string, AccountMetadata>({
39 path: DB_NAME,
40 schema: AccountMetadataSchema,
41 ttl: 60_000 * 10, // 1 hour
42 max: 1000, // Maximum 1000 entries
43 log: LOGGING_ENABLED // Enable logging
44})
45
46export { identityCache, accountMetadataCache };
47export type { AccountMetadata };
48export default identityCache;