Session Studio

Cache invoice PDFsbilling-svc

Invoice PDFs are rendered on every download. Cache them by invoice id and version, and clear the cache when an invoice changes.

I'll find where PDFs are rendered, add a cache keyed by id and version, then run the invoice tests.

Readsrc/invoices/pdf.tsRead 88 lines
Readsrc/invoices/events.tsRead 41 lines
Editsrc/invoices/pdf.ts
+const cache = new Map<string, Buffer>();+const key = `${inv.id}@${inv.version}`;+if (cache.has(key)) return cache.get(key)!;-return render(inv);+const pdf = await render(inv);+cache.set(key, pdf);+return pdf;
Editsrc/invoices/events.ts
+onInvoiceChanged((id) => clearPdf(id));
Bash$ npm test -- invoices

← Session Studio