Caching with dynamic data source, best practice? #288
Replies: 12 comments 1 reply
-
Check here https://github.com/ngneat/elf/blob/master/packages/requests/src/lib/request-data-source.spec.ts#L94 |
Beta Was this translation helpful? Give feedback.
-
Thanks for answering! Yes I have, but I still do not see what is not correctly setup in my linked sample, or what I am doing wrong. Did you look at my linked sample illustration the caching issue? |
Beta Was this translation helpful? Give feedback.
-
That makes sense. You're calling both immediately, but the response of the first one isn't returned, so when you call the second one, it isn't yet cached. |
Beta Was this translation helpful? Give feedback.
-
You're looking for concurrent request functionality. This is related to cache. You can create a |
Beta Was this translation helpful? Give feedback.
-
Ahh, true, of course, good idea with a skipWhilePending, will that be part of the elf framework anytime soon? Now to my original problem that I was trying to replicate in a sample, I have updated it. Now I first fetch 10 items, id 1-10, and then I can see that requests with specific ids are skipped since already in cache, but why is the request with an id not in cache not executed, like my id 14 in this case? |
Beta Was this translation helpful? Give feedback.
-
You're welcome to create a feature request or create a PR. |
Beta Was this translation helpful? Give feedback.
-
I see |
Beta Was this translation helpful? Give feedback.
-
@NetanelBasal please don't close this yet, seems that seems very strange, I don't see it, it never gets executed, also tested in in firefox, and asked a collegue testing the same code on his computer, todo '14' fetched is never executed with the provided sample code. If I comment out the fetchTodos() I see it. |
Beta Was this translation helpful? Give feedback.
-
It's because you set the |
Beta Was this translation helpful? Give feedback.
-
Okay, I see, then I misunderstand something completely I guess. Since removing group key does not make it think any of the entities are cached after fetchTodos, when fetchingTodo with individual id. I thought it would be possible to use the caching in a way that elf would look among the entities in store and compare with key/id and if already in store it would not fetch it but otherwise it would. How would you configure the store and data sources to support what I am after? Thanks! |
Beta Was this translation helpful? Give feedback.
-
Update the cache when you call both tods and individual todo. |
Beta Was this translation helpful? Give feedback.
-
I see, so caching is purely based on the keys you specify yourself manually, nothing ever looks in the store to see if there is an entity actually in the store with a machine id/key property and value. Is this the recommended way to do it then? |
Beta Was this translation helpful? Give feedback.
-
Which @ngneat/elf-* package(s) are the source of the bug?
requests-cache, requests-data-source
Is this a regression?
No
Description
The documentation and examples are a bit different, but I do not get it to work with any of the following, but I might be something terrible wrong here...
Please provide a link to a minimal reproduction of the bug
https://codesandbox.io/s/quiet-star-56m5ii
Please provide the exception or error you saw
Please provide the environment you discovered this bug in
No response
Anything else?
No response
Do you want to create a pull request?
No
Beta Was this translation helpful? Give feedback.
All reactions