TestGlobalCache Class — drizzle-orm Architecture
Architecture documentation for the TestGlobalCache class in sqlite-common-cache.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 271b550c_f48f_806e_3db7_b135393b905d["TestGlobalCache"] 7f26f618_3381_4763_89e6_6503ea1e3ebd["sqlite-common-cache.ts"] 271b550c_f48f_806e_3db7_b135393b905d -->|defined in| 7f26f618_3381_4763_89e6_6503ea1e3ebd cbd2e140_79ca_c81c_8eab_756585bd4329["constructor()"] 271b550c_f48f_806e_3db7_b135393b905d -->|method| cbd2e140_79ca_c81c_8eab_756585bd4329 2d916d14_f216_c07f_365e_8b6c5045a07b["strategy()"] 271b550c_f48f_806e_3db7_b135393b905d -->|method| 2d916d14_f216_c07f_365e_8b6c5045a07b 6dd7df64_a578_fb06_ae89_e2b614e35db3["get()"] 271b550c_f48f_806e_3db7_b135393b905d -->|method| 6dd7df64_a578_fb06_ae89_e2b614e35db3 e8b0cfeb_03aa_ee48_7054_24caf684e6fe["put()"] 271b550c_f48f_806e_3db7_b135393b905d -->|method| e8b0cfeb_03aa_ee48_7054_24caf684e6fe fca810d8_d38d_c495_16b6_7cd167bef179["onMutate()"] 271b550c_f48f_806e_3db7_b135393b905d -->|method| fca810d8_d38d_c495_16b6_7cd167bef179
Relationship Graph
Source Code
integration-tests/tests/sqlite/sqlite-common-cache.ts lines 10–68
export class TestGlobalCache extends Cache {
private globalTtl: number = 1000;
private usedTablesPerKey: Record<string, string[]> = {};
constructor(private kv: Keyv = new Keyv()) {
super();
}
override strategy(): 'explicit' | 'all' {
return 'all';
}
override async get(key: string, _tables: string[], _isTag: boolean): Promise<any[] | undefined> {
const res = await this.kv.get(key) ?? undefined;
return res;
}
override async put(
key: string,
response: any,
tables: string[],
isTag: boolean,
config?: CacheConfig,
): Promise<void> {
await this.kv.set(key, response, config ? config.ex : this.globalTtl);
for (const table of tables) {
const keys = this.usedTablesPerKey[table];
if (keys === undefined) {
this.usedTablesPerKey[table] = [key];
} else {
keys.push(key);
}
}
}
override async onMutate(params: MutationOption): Promise<void> {
const tagsArray = params.tags ? Array.isArray(params.tags) ? params.tags : [params.tags] : [];
const tablesArray = params.tables ? Array.isArray(params.tables) ? params.tables : [params.tables] : [];
const keysToDelete = new Set<string>();
for (const table of tablesArray) {
const tableName = is(table, Table) ? getTableName(table) : table as string;
const keys = this.usedTablesPerKey[tableName] ?? [];
for (const key of keys) keysToDelete.add(key);
}
if (keysToDelete.size > 0 || tagsArray.length > 0) {
for (const tag of tagsArray) {
await this.kv.delete(tag);
}
for (const key of keysToDelete) {
await this.kv.delete(key);
for (const table of tablesArray) {
const tableName = is(table, Table) ? getTableName(table) : table as string;
this.usedTablesPerKey[tableName] = [];
}
}
}
}
}
Domain
Source
Frequently Asked Questions
What is the TestGlobalCache class?
TestGlobalCache is a class in the drizzle-orm codebase, defined in integration-tests/tests/sqlite/sqlite-common-cache.ts.
Where is TestGlobalCache defined?
TestGlobalCache is defined in integration-tests/tests/sqlite/sqlite-common-cache.ts at line 10.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free