Next.js Discord

Discord Forum

Help with speeding up API route response

Answered
English Angora posted this in #help-forum
Open in Discord
English AngoraOP
I have this API route that returns the number of views for a particular blog post. I'm using a KV database. Chat GPT is recommending I use a memoize function but that doesn't seem right.
https://chat.openai.com/share/c578a384-dd6d-4614-98c0-788429624719

I'm thinking this could all just be the result of cold starts.

API route code:
https://github.com/M-Valentino/M-Valentino_NextJS/blob/main/src/pages/api/blog-post-views.js

Component that calls the API route:
https://github.com/M-Valentino/M-Valentino_NextJS/blob/main/src/components/blogComponents/BlogPostHeader.tsx
Answered by Scottish Fold
View full answer

5 Replies

English AngoraOP
English AngoraOP
bump
Scottish Fold
Answer
Scottish Fold
or you can cache permanently with
fetch('https://...', { next: revalidate: false, tags: ["blog-views"] })


Then only revalidate when a new view is added using
revalidateTag("blog-views")
English AngoraOP
I didn't know this was a thing. Thanks!