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

Add ability to use a cache key for useLoader #3149

Open
mynameisgump opened this issue Jan 10, 2024 · 1 comment
Open

Add ability to use a cache key for useLoader #3149

mynameisgump opened this issue Jan 10, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@mynameisgump
Copy link

In the useLoader function in hooks.tsx, currently the URL is used as the key in order to cache the gltf using the suspend function from the suspend-react library. My problem is that I have a url with a changing saastoken, so each time I go to the page it will re-download and cache a new version of the file. Would it be possible to have an optional cache key that's different to the URL which it would check for and return instead? That way even if the url is different due to some form of api auth it would still return the cached glb when the function is called again. I've written a somewhat similar hook to useGLTF from the react-drei library that uses the same idea to cache the object:

const useNewLoader = ({ url, cacheKey }: IUseNewLoader) =>
  suspend(
    async () =>
      new Promise<GLTF>((res, reject) => {
        gltfLoader.load(url, (data) => {
          if (data.scene) Object.assign(data, buildGraph(data.scene));
          res(data);
        });
      }).finally(() => (gltfLoader as any).dispose?.()),
    ['glb', cacheKey]
  ) as GLTF & ObjectMap;

export default useNewLoader;
@CodyJasonBennett CodyJasonBennett added the enhancement New feature or request label Apr 26, 2024
@CodyJasonBennett
Copy link
Member

You can append a query url with a cache key currently, although cache behavior in general could be bettered with React 19. cc @drcmda

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

2 participants