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

[Feature] Fetch on cache miss #934

Open
bradjones1 opened this issue Mar 1, 2022 · 0 comments
Open

[Feature] Fetch on cache miss #934

bradjones1 opened this issue Mar 1, 2022 · 0 comments

Comments

@bradjones1
Copy link
Contributor

Brainstorming here, would it be worthwhile to explore a fetch-on-miss type functionality for memory source caches? Or would that be too difficult given sync vs. async, etc?

My current problem space is a React Native screen that might be navigated to, directly, or from a prior screen that might have already fetched the resource in question. So I have:

useEffect(() => {
  const profileQuery = q => q.findRelatedRecord(props.introduction.relationships.initiator.data, 'dating_profile');
  const profile = props.dataStore.cache.query(profileQuery);
  // We may have navigated here directly...
  if (profile) {
    setProfile(profile);
  }
  else {
    __DEV__ && console.log('Fetching profile');
    props.dataStore.query(profileQuery)
      .then(profile => setProfile(profile));
  }
}, []);

Which is my approach at doing a manual fetch on cache miss... is it worth exploring something like this natively in Orbit?

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

1 participant