Skip to content

feat: usar "stale-while-revalidate" para "[cep].js" - #30

Merged
filipedeschamps merged 2 commits into
BrasilAPI:masterfrom
paulogdm:patch-1
Feb 24, 2020
Merged

filipedeschamps merged 2 commits into
BrasilAPI:masterfrom
paulogdm:patch-1

Conversation

@paulogdm

Copy link
Copy Markdown
Collaborator

Docs aqui 👉 LINK.

Basicamente, podemos usar a cache do ZEIT Now de maneira um pouco mais inteligente. O comportamente aqui é quase o mesmo do que apenas usar "s-maxage" mas sempre vamos garantir respostas rápidas a partir do primeiro request. Servimos o que a "cache tem" enquanto a plataforma revalida a informação no background.

Stale-while-revalidate

Uso prático: https://zeit.co/blog/serverless-pre-rendering (depreciado em breve por iSSG https://notion-blog.now.sh/).

@vercel

vercel Bot commented Feb 23, 2020 •

Copy link
Copy Markdown

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/filipedeschamps/brasilapi/gz90wrwq3
✅ Preview: https://brasilapi-git-fork-paulogdm-patch-1.filipedeschamps.now.sh

@paulogdm paulogdm changed the title Usar "stale-while-revalidate" para "[cep].js" feat: usar "stale-while-revalidate" para "[cep].js" Feb 23, 2020
@filipedeschamps

Copy link
Copy Markdown
Member

Sensacional @paulogdm !!! Procurei na documentação e não encontrei: você sabe dizer o que acontece se o backend responder com erro? A CDN continua respondendo a versão stale? Eu assumo que sim por conta dessa parte:

Your backend functions and datasources can go down, and you will likely tolerate their downtime

Só fiquei confuso com o que significa exatamente a parte do "will likely tolerate". Se ele tolerar mesmo que o s-maxage tenha sido atingido, vai ser sensacional!!!

@paulogdm

paulogdm commented Feb 23, 2020 •

Copy link
Copy Markdown
Collaborator Author

O header explícito seria stale-if-error, que o ZEIT Now não suporta mas stale-while-revalidate já assume esse comportamento. Então sim, caso ocorra algum erro a plataforma continuará mandando conteúdo "stale". Porém note que se você sofrer um cache purge e sua API ainda estiver degradada, seu usuário receberá um 5XX.

@filipedeschamps

Copy link
Copy Markdown
Member

Sensacional! Faz total sentido 👍

Merging!

@LorhanSohaky

LorhanSohaky commented Jul 13, 2020 •

Copy link
Copy Markdown
Member

Sensacional

This branch was successfully deployed

1 active deployment
Preview — 1357c215 Deployed Feb 23, 2020 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants