Skip to content

feat: add experimental support for TTL #833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 25, 2021
Merged

feat: add experimental support for TTL #833

merged 8 commits into from
Nov 25, 2021

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Nov 23, 2021

Summary

Adds experimental support for ttl in pages with revalidate set. Parses the cache-control header returned by Next and extracts the s-maxage value, which it then uses in the ttl response. This isnlt enabled by default, but requires an env var flag.

As part of the build process we need to patch the next-server.js file, because we need to disable caching for ISR pages and currently this is only supported for minimalMode. We do this by adding another env var to the line where it checks for all the conditions for disabling the SSG cache.

Test plan

  1. Visit a page with revalidate set. The rendered-at time will probably be old. If the rendered-at time is the current wall time then it's a fresh deploy so wait a minute for it to be stale then load again.
  2. Wait for 1 minute for the revalidated content to propagate to your edge node
  3. Load the page again. The rendered-at time should match the time at step 1 (so about a minute in the past)

Relevant links (GitHub issues, Notion docs, etc.) or a picture of cute animal

image

@github-actions github-actions bot added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Nov 23, 2021
@ascorbic ascorbic requested review from emilyzhang and a team November 24, 2021 12:31
@ascorbic ascorbic changed the title feat: wip ttl support feat: add experimental support for TTL Nov 24, 2021
@ascorbic ascorbic force-pushed the mk/ttl-support branch 8 times, most recently from 1a30536 to 8e441e3 Compare November 25, 2021 08:35
@ascorbic ascorbic marked this pull request as ready for review November 25, 2021 10:11
Release-as: 4.0.0-beta.12
@ascorbic ascorbic self-assigned this Nov 25, 2021
@ascorbic ascorbic requested a review from tiffafoo November 25, 2021 14:23
const multiValueHeaders: Record<string, Array<string>> = {}
for (const key of Object.keys(headers)) {
if (Array.isArray(headers[key])) {
multiValueHeaders[key] = headers[key] as Array<string>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do the following instead so you don't need to coerce

    const header = headers[key];

    if (Array.isArray(header)) {
      multiValueHeaders[key] = header
    } else {
      multiValueHeaders[key] = [header]
    }

@ascorbic ascorbic requested a review from tiffafoo November 25, 2021 14:35
@@ -219,6 +219,57 @@ exports.moveStaticPages = async ({ netlifyConfig, target, i18n }) => {
}
}

const patchFile = async ({ file, from, to }) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooo neat

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate it!

Copy link

@tiffafoo tiffafoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the wait, I thought I clicked the thing. Looks awesome 😮!

@kodiakhq kodiakhq bot merged commit 14ca14a into main Nov 25, 2021
@kodiakhq kodiakhq bot deleted the mk/ttl-support branch November 25, 2021 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants