mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-14 13:27:13 +00:00
The preview route already returns 304 in under a millisecond when a browser presents a matching ETag, but it never remembered its own output. Any browser without a cached copy — every first open of a session, and every gate run — re-paid the linkedom parse, ensureHfIds and sub-composition inlining, roughly 450ms of the measured preview build at 3,000 clips. Keep the built document in a small in-process LRU keyed on the same project signature the ETag is derived from, so freshness keeps exactly one owner: a cache hit is a document the ETag would have revalidated to a 304. Bounded by entry count and total bytes, evicting least-recently-used. The subtle part is the hf-id write-back. persistHfIdsIfNeeded rewrites the source file when it mints ids, which changes the project signature; the signature is therefore re-resolved after the stamp and that post-stamp value now feeds the cache key, the served ETag and the injected signature meta tag alike. Previously the response carried the pre-stamp ETag, so the second request disagreed with it and always rebuilt. The bundle-failure fallback is deliberately not memoized: it produces the degraded, un-inlined document, is already the cheap path, and caching it would pin a transient bundler failure until the project changed.