Add Cache primtive
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { AESKey } from '../src/crypto/aes-key.js';
|
||||
import { StorageMemory, EncryptedStorage, type BaseStorage } from '../src/storage/index.js';
|
||||
import { BTreeCache, KvCache } from '../src/cache/index.js';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helpers
|
||||
@@ -161,9 +162,19 @@ const DOC_COUNTS = [1_000, 10_000, 50_000];
|
||||
for (const count of DOC_COUNTS) {
|
||||
const docs = generateDocs(count);
|
||||
|
||||
// Indexes on id, name, AND age — range queries on age use B+ Tree.
|
||||
const indexedWithAge = StorageMemory.from<Doc>(['id', 'name', 'age']);
|
||||
await benchmarkStorage('StorageMemory (indexed: id,name,age)', indexedWithAge, docs, { hasAgeIndex: true });
|
||||
// Indexes on id, name, AND age with explicit B+ Tree cache.
|
||||
const indexedWithAgeBTree = StorageMemory.from<Doc>(
|
||||
['id', 'name', 'age'],
|
||||
new BTreeCache(),
|
||||
);
|
||||
await benchmarkStorage('StorageMemory (B+Tree cache, indexed: id,name,age)', indexedWithAgeBTree, docs, { hasAgeIndex: true });
|
||||
|
||||
// Same indexes, but KV cache (no range support).
|
||||
const indexedWithAgeKv = StorageMemory.from<Doc>(
|
||||
['id', 'name', 'age'],
|
||||
new KvCache(),
|
||||
);
|
||||
await benchmarkStorage('StorageMemory (KV cache, indexed: id,name,age)', indexedWithAgeKv, docs);
|
||||
|
||||
// Indexes on id, name only — range queries on age fall back to full scan.
|
||||
const indexed = StorageMemory.from<Doc>(['id', 'name']);
|
||||
|
||||
Reference in New Issue
Block a user