perf(cache): short TTL for gallery image listings#513
Merged
Conversation
The public gallery image-list caches (`gallery` tag) are the only cached reads whose freshness depends on a background source: the preprocess ticker flips `variants_ready` outside request scope and therefore cannot call `revalidateTag` (Next throws "Invariant: static generation store missing" with no work store). Those updates were only picked up when the 1h safety-net TTL expired, so a freshly-processed image could keep showing its placeholder for up to an hour after its variants were ready. Give the four `gallery`-tagged wrappers their own 60s TTL while leaving albums/config at 1h. Albums and config only change via admin writes that bust their tags synchronously in request scope, so they keep the long safety-net TTL. Admin writes still invalidate the gallery tag instantly via `revalidateGalleryCache`; the short TTL only bounds the background-ticker gap (now <=60s) and still absorbs the bulk of repeat reads, so page-1 first paint stays a cache hit for most requests.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
The public gallery image-list caches (the
gallerytag inserver/lib/cache.ts) are the only cached reads whose freshness depends on a background source. The preprocess ticker flipsvariants_readyoutside request scope, so it cannot callrevalidateTag— Next throwsInvariant: static generation store missingwhen there is no work store. As a result, that update was only picked up when the 1h safety-net TTL expired, so a freshly-processed image could keep showing its placeholder for up to an hour after its variants were actually ready.Change
Give the four
gallery-tagged wrappers their own 60s TTL, while leaving thealbumsandconfigcaches at 1h.albums/configonly change via admin writes, which bust their tags synchronously in request scope — so a long safety-net TTL remains fine for them.gallerytag instantly viarevalidateGalleryCache(image create / update / delete / show-hide / sort). The short TTL only bounds the background-ticker gap, now ≤60s instead of ≤1h.Why option ① (short TTL) over the alternatives
getImagesData(1, album)during page render, so the image-list cache helps first paint — dropping it adds a DB query there.Short TTL is one line per wrapper, keeps the page-1 first-paint cache hit, and bounds staleness to ≤60s.
Scope / risk
albums/config, no change to the auth/render model.