Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TheWebDevel/5dcd46b8360b637083b699e59d886baa to your computer and use it in GitHub Desktop.
Save TheWebDevel/5dcd46b8360b637083b699e59d886baa to your computer and use it in GitHub Desktop.
indexdb-prompt
/**
* GitHub Copilot prompt
*
* Goal: implement a performant frontend cache for huge PDF‑diff JSON blobs.
*
* Requirements
* — Tech: TypeScript + React, Dexie.js (IndexedDB wrapper), lz‑string, Web Worker.
* — Key format: `${pathname}/${fileName}?v1=${ver1}&v2=${ver2}` (strip base URL first).
* — API surface:
* • generateCacheKey(pathname: string, file: string, ver1: string, ver2: string): string
* • saveDiff(key: string, json: string): Promise<void> // compress→store
* • loadDiff(key: string): Promise<object|null> // read→decompress→parse
* • purgeOld(days = 30): Promise<number> // delete entries older than TTL
* — Worker: parses + compresses JSON off‑main‑thread; posts back Uint8Array & parsed object.
* — Storage schema: { id (PK), payload (Uint8Array), createdAt (number ms) }.
* — Optimizations: structuredClone to transfer Uint8Array, Dexie bulk delete, relaxed durability off.
*
* Deliverables
* 1. cache.ts – Dexie DB, helper fns, TTL purge.
* 2. diffWorker.ts – Web Worker doing JSON.parse + lz-string compression.
* 3. usePdfDiff.ts – React hook: given URLs & versions, returns diff (hits cache or computes).
*
* Keep code concise, typed, and ready to drop into a Vite React project.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment