Skip to content

[BUG] accessControlProvider cacheTime does not seem to be working #6749

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

Open
omerdn1 opened this issue Apr 14, 2025 · 3 comments · May be fixed by #6753
Open

[BUG] accessControlProvider cacheTime does not seem to be working #6749

omerdn1 opened this issue Apr 14, 2025 · 3 comments · May be fixed by #6753
Labels
bug Something isn't working

Comments

@omerdn1
Copy link

omerdn1 commented Apr 14, 2025

Describe the bug

Hi, I have the following Refine setup:

        <Refine
          routerProvider={routerProvider}
          authProvider={authProviderClient}
          dataProvider={dataProvider}
          liveProvider={liveProvider(supabaseBrowserClient)}
          notificationProvider={useNotificationProvider}
          accessControlProvider={{
            can,
            options: {
              buttons: {
                hideIfUnauthorized: true,
              },
              queryOptions: {
                staleTime: 5 * 60 * 1000, // 5 minutes
                cacheTime: 5 * 60 * 1000, // 5 minutes
              }
            }
          }}
          i18nProvider={i18nProvider}
          resources={[
            {
              name: "home",
              list: "/",
              options: {
                hide: true,
              }
            },
            {
              name: "admin",
              list: "/admin",
              meta: { role: "admin" },
              options: {
                hide: true,
              }
            },
            {
              name: "agent",
              list: "/agent",
              meta: { role: "agent" },
              options: {
                hide: true,
              }
            },
            {
              name: "customer_support",
              list: "/customer-support",
              meta: { role: "customer_support" },
              options: {
                hide: true,
              }
            },
            {
              name: "printing_house",
              list: "/printing-house",
              meta: { role: "printing_house" },
              show: "/printing-house/show/:id",
              options: {
                // hide: true,
              }
            },
        >
          {children}
          <RefineKbar />
        </Refine>

When I'm loading a page -- for example -- /printing-house, the can function runs every time for each resource and if the current route is wrapped with CanAccess then it waits for the execution of the can function for all resources, which makes loading of pages very slow...
I tried using cacheTime to cahce the results but does not seem to do anything. The can function still runs for each resource and the slow behavior keeps occuring.

Steps To Reproduce

  1. Copy my setup
  2. Wrap a route with CanAccess
  3. Initial load
  4. Reload page and see if can still runs again and if it's slow

Expected behavior

Resource control needs to be determined on first run and then cached for the cache time.

Packages

  • @refinedev/antd
  • @refinedev/nextjs

Additional Context

Additionally, I was wondering if there is a way to prioritize checking access for the current resource and then showing it immediately instead of having to wait for all the checks. That would solve the issue as well.

@omerdn1 omerdn1 added the bug Something isn't working label Apr 14, 2025
@pks2906
Copy link

pks2906 commented Apr 15, 2025

I want to work on this issue, kindly assign the bug

@O-BERNARDOFOEGBU

This comment has been minimized.

@alicanerdurmaz
Copy link
Member

Hello @omerdn1, Thanks for the detailed explanation

Actually, TanStack Query already has a very good caching mechanism. If you’re making repeated requests, it’s probably because the query key is changing. For example, you’ll be making requests again and again for different resources because the query key changes.

I don’t think this is a bug but rather an issue in your implementation. If you share a reproducible example, I can help debug it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants