Skip to content
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

[Question?] cache key failed to generate on Next.js app router #914

Closed
mnpqraven opened this issue Nov 8, 2023 · 4 comments
Closed

[Question?] cache key failed to generate on Next.js app router #914

mnpqraven opened this issue Nov 8, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@mnpqraven
Copy link

mnpqraven commented Nov 8, 2023

Is your feature request related to a problem? Please describe.
I'm relatively new to Connect and have been following the tutorial to implement rpc in my Next.js app.
Considering the following

export function rpc<T extends ServiceType>(service: T): PromiseClient<T> {
  const client = createPromiseClient(
    service,
    createGrpcWebTransport({
      baseUrl: "https://randomurl.com",
    })
  );
  return client;
}

I'm getting cache errors from next saying that caching for this call failed (hsr.dev is my nextjs app and nas-ws is my rust backend server with the rpc endpoints)
image

Describe the solution you'd like
I was wondering if this is a misconfiguration on my part or caching is not yet supported for Next.js, or if caching rpc is not possible in general

@mnpqraven mnpqraven added the enhancement New feature or request label Nov 8, 2023
@srikrsna-buf
Copy link
Member

I am not familiar with nextjs caching strategy but my guess is that it doesn't support post requests and grpc web works on post

@srikrsna-buf
Copy link
Member

I can confirm that cache only applies to GET requests from this doc. The connect protocol supports GET requests, if you can switch to connect protocol then GET requests (and therefore caching) can be enabled on a per rpc basis.

Let us know if you run into any problems, closing this for now feel free reach out if I missed something.

@arpitBhalla
Copy link

I'm calling GET requests, but caching doesn't work for me
image

export const fetchInfo = cache(async (id: string) => {
    return await client.getInfo({id});
});
export async function generateMetadata({params, searchParams}: PageProps) {
    const insight = await fetchInfo(params.id);
    return generateInsightMetadata(insight);
}

@srikrsna-buf
Copy link
Member

If you are using the cache function it shouldn't matter if it is a get/post request. Does the error also tell you why it failed to create the cache key?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants