Skip to content

IndexedDB-Backed Persistent Invoice Cache #555

Description

@Kingsman-99

Description

The current client-side caching strategy relies on localStorage, which is capped at ~5 MB and synchronous, causing jank when reading large invoice lists. Migrating to IndexedDB gives the app an asynchronous, quota-managed store that can hold much larger datasets and supports structured queries, enabling faster cold-start rendering.

Technical Context

New abstraction layer at src/lib/db/invoiceCache.ts wrapping the browser's indexedDB API (or the idb npm package for promise ergonomics). The useInvoices hook in src/hooks/useInvoices.ts is updated to read from IndexedDB first, then hydrate from the API and write back. A src/lib/db/schema.ts file defines the object store names, key paths, and index definitions. Cache invalidation is tied to the invoice updatedAt timestamp.

Acceptance Criteria

  • Invoice list data is stored in an IndexedDB object store named invoices with id as the key path and an index on status
  • On cold page load the UI renders cached data from IndexedDB before the API response arrives, reducing perceived latency
  • Cache entries are invalidated and replaced when the API returns a newer updatedAt timestamp
  • The store handles quota-exceeded errors gracefully, falling back to a network-only fetch and surfacing a non-blocking warning toast
  • A manual "Clear cache" button in settings wipes all IndexedDB stores without requiring a browser hard-reload
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions