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 option to skip cache if result not found #69

Closed
dcworldwide opened this issue Jan 16, 2017 · 3 comments
Closed

Add option to skip cache if result not found #69

dcworldwide opened this issue Jan 16, 2017 · 3 comments

Comments

@dcworldwide
Copy link

If you have the following events:

DataLoader. load(1) // returns null
Some code then inserts 1
DataLoader.load(1) // returns null, even though the record exists.

What to do here? Is there an elegant way to clear the cache for keys that returned null?

@ThisIsMissEm
Copy link

Do you do this in a single request lifecycle? If so, use myLoader.clear(key), if you're sharing the dataloader instance between requests, see #62

@dcworldwide
Copy link
Author

Yeah thanks. I've learned that I need to clear on mutation. Or...clear if load returns null.

@leebyron
Copy link
Contributor

Typically returning null from a load implies that the value with that key is known not to exist, which is different from not being found, the first is a successful load (of an empty result) while the latter is an errored load. Cache behavior is key to this difference. For instance, if something is known not to exist, repeatedly fetching it would be unhelpful.

Having your batch function throw/return an Error when values have failed to load will ensure the cache is skipped.

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