-
Hello, How can I know if data response was from cached result or new fetched result? I looked at this Stackoverlfow thread but this is maybe outdated? my client setup looks like this:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Are you referring to the response from your own server being from cache? Or the data shown by urql if you have a https://formidable.com/open-source/urql/docs/basics/document-caching/#request-policies |
Beta Was this translation helpful? Give feedback.
-
tl;dr:
In short It's a common mistake to assume that we care about whether a single result or field is “cached”. But in practice, this doesn't match UI/user expectations. For a longer explanation read the long explanation of how this works in Generally, bindings in The To take a step back, lacking a use-case here, let me quickly outline how the cache approach works today. Especially since we don't have a single cache offering, but it's configurable. Basically, the execution in exchanges are split into two group: asynchronous exchanges (e.g. synchronous exchanges (e.g. Hence, the difference here is timing. To simplify this then, First, before moving on, this means that you can in theory create your own This is reflected in the bindings and The result of this, while ignoring the bindings is that we can look at three separate APIs on the client.query(...).toPromise();
client.query(...).subscribe(result => { /*...*/ });
client.readQuery(...); The first API, The second API, The third API, Now, what does that mean for bindings? In the UI, saying whether something is cached is actually not very useful, because UI semantics don't match caches. A render can be repeated and if we assumed that we wanted to display it, the next time we display data it's always cached since every request to the API documents the cache. What we found is that bindings (i.e. the UI) care about only two states: fetching and stale. The UI may want to display a loading indicator when it's The This actually leads nicely into the This also extends to Graphcache. If we for instance use In short, This more closely hence matches our expectations for what the UI will show, |
Beta Was this translation helpful? Give feedback.
tl;dr:
requestPolicyExchange
, or a custom approach, that setscache-and-network
to update data when it's getting “old” works@_optional
) then in the formerfetching: true
will be set, and in the latterstale: true
will be setIn short
stale: true
tells you whether a fresh background request for new data is ongoing.It's a common mistake to assume that we care about whether a single result or field is “cached”. But in practice, this doesn't match UI/user expectations.
For a longer explanati…