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

cache no-store not work #83

Closed
hmz22 opened this issue Aug 13, 2023 · 5 comments
Closed

cache no-store not work #83

hmz22 opened this issue Aug 13, 2023 · 5 comments

Comments

@hmz22
Copy link

hmz22 commented Aug 13, 2023

I create project with your guide but when use getClient cached

page.tsx

import ContentCard from '@/components/common/ContentCard'
import PageHeaderCard from '@/components/common/PageHeaderCard'
import { GET_MEMBERS } from '@/graphql/query/member.query'
import { getClient } from '@/lib/client'
import React from 'react'
import Paginate from './paginate'


export const dynamic = "force-dynamic";

type Props = { searchParams: any }
async function getData({ page, limit }: { page: number, limit: number }) {
   
    const res = await getClient().query({
        query: GET_MEMBERS, variables: {
            options: {
                paginate: {
                    page: page,
                    limit
                }
            }
        },
    })

    console.log(res.data)

    return res.data
}

async function MemberPage({ searchParams }: Props) {
    console.log(searchParams)

    const data = await getData({
        limit: searchParams.limit ? searchParams.limit : 5,
        page: searchParams.page ? parseInt(searchParams.page) : 1
    })

    return (
        <>
            <PageHeaderCard title='Members'>
                <></>
            </PageHeaderCard>
            <ContentCard>
                <ul>
                    {data.members.docs.map((i) => (
                        <li key={i._id}>{i.firstname}</li>
                    ))}
                </ul>

                <Paginate />
            </ContentCard>
        </>
    )
}

export default MemberPage

and this my client.ts

import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client";
import { registerApolloClient } from "@apollo/experimental-nextjs-app-support/rsc";
import { headers } from "next/headers";

export const { getClient } = registerApolloClient(() => {
  const headersInstanse = headers();
  return new ApolloClient({
    cache: new InMemoryCache(),
    link: new HttpLink({
      headers: {
        "Apollo-Require-Preflight": "true",
        cookie: headersInstanse.get("cookie") ?? "",
      },
      uri: `${process.env.NEXT_PUBLIC_SERVER_HOST}/graphql`,
      credentials: "include",
      fetchOptions: { cache: "no-store" },
    }),
  });
});

when change page and back prev page (for example change page from 1 to 2 and then back to 1) data is cached and this my problem

@plausible-phry
Copy link

This might be the Next.js router browser side caching - as far as I know, the client-side router will cache results between navigations for 60 seconds and not make the same request again.

You can read about that here:
https://nextjs.org/docs/app/building-your-application/caching#4-nextjs-caching-on-the-client-router-cache

@hmz22
Copy link
Author

hmz22 commented Aug 15, 2023

Is there a solution for it or related issue for it in next.js github issue section?

@plausible-phry
Copy link

You would have to check that with Next.js, but I believe that is working as they intended - although not everyone likes it.

@phryneas
Copy link
Member

I'm doing some housekeeping so I'm closing some older issues that haven't seen activity in a while.
If this is still relevant, please feel free to reopen the issue.

Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

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

No branches or pull requests

3 participants