unstable_cache
Answered
British Shorthair posted this in #help-forum
British ShorthairOP
I am using the unstable_cache for a server action. However its not being cached.
Does someone has an idea why?
Does someone has an idea why?
20 Replies
@British Shorthair I am using the unstable_cache for a server action. However its not being cached.
Does someone has an idea why?
you have
export const fetchCache = 'force-no-store' on the route?British ShorthairOP
No I dont..
for the getSearchResultsById(), I am using a supabase server comonent client wich uses the cookies, could this be the issue?
@British Shorthair for the getSearchResultsById(), I am using a supabase server comonent client wich uses the cookies, could this be the issue?
do you still see it if you refresh the page?
British ShorthairOP
Sorry, see what if the page refresh?
British ShorthairOP
Only on a hard refresh
@British Shorthair Only on a hard refresh
yes it is expected
British ShorthairOP
So its caching then?
it only fetch again if you hard refresh
British ShorthairOP
Check, thanks Ray
British ShorthairOP
Hey Ray the docs say:
keyParts: This is an array that identifies the cached key. It must contain globally unique values that together identify the key of the data being cached. The cache key also includes the arguments passed to the function.
However I cannot use the id in the keyParts. Do you know why?
keyParts: This is an array that identifies the cached key. It must contain globally unique values that together identify the key of the data being cached. The cache key also includes the arguments passed to the function.
However I cannot use the id in the keyParts. Do you know why?
@British Shorthair Hey Ray the docs say:
keyParts: This is an array that identifies the cached key. It must contain globally unique values that together identify the key of the data being cached. The cache key also includes the arguments passed to the function.
However I cannot use the id in the keyParts. Do you know why?
the id is included to the key part as the doc says
The cache key also includes the arguments passed to the function.
but if you want to set a unique tag, you can do this
export const getData = (id: string) => {
return unstable_cache(
async (id: string) => {
...
},
[`searches`],
{ tags: [`searches-${id}`], revalidate: 10 }
)(id);
};British ShorthairOP
Thanks!
British ShorthairOP
Hey @Ray could you confirm this?
I have the following workflow:
1. A form on the '/search/' page adds a row in a supabase table
2. triggers an AWS Lambda function.
3. revalidatesTag('searches')
4. then redirects to '/searches/'.
5. The '/searches/' page displays the right data.
When the AWS lambda is done:
1. It updates the same record in the db.
2. Supabase sends webhook to api route /searches
3. In the API handler it will revalidateTag('searches')
4. When I refresh I see the updates search.
Q: Is it possible to show the updated table without a refresh? I would think its not possible, since its a server component. But I am not sure.
I have the following workflow:
1. A form on the '/search/' page adds a row in a supabase table
2. triggers an AWS Lambda function.
3. revalidatesTag('searches')
4. then redirects to '/searches/'.
5. The '/searches/' page displays the right data.
When the AWS lambda is done:
1. It updates the same record in the db.
2. Supabase sends webhook to api route /searches
3. In the API handler it will revalidateTag('searches')
4. When I refresh I see the updates search.
Q: Is it possible to show the updated table without a refresh? I would think its not possible, since its a server component. But I am not sure.
British ShorthairOP
Check, thanks