refine icon indicating copy to clipboard operation
refine copied to clipboard

[BUG] accessControlProvider cacheTime does not seem to be working

Open omerdn1 opened this issue 8 months ago • 3 comments

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 avatar Apr 14 '25 15:04 omerdn1

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

pks2906 avatar Apr 15 '25 07:04 pks2906

uwc

O-BERNARDOFOEGBU avatar Apr 15 '25 20:04 O-BERNARDOFOEGBU

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.

alicanerdurmaz avatar Apr 21 '25 12:04 alicanerdurmaz

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 20 '25 13:06 stale[bot]