question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discussion with cache stale and network error

See original GitHub issue

From what I understand from the documentation, when cachePolicy = cache-first and cacheLife > 0, the cached data is returned if it has not expired. If the cache has expired, a request is made on the server.

Doubt: If there is an error in the request (such as, for example, a cell phone went offline), the error is returned, but not the cache?

Another question, where is the cache? In memory? If I use the library in react native and place a 24-hour cache, after obtaining the data in a request I close the application and open it again, is a request made?

Another thing, how does the cache with pagination work? If the data is not stale, is only the first page returned?

That said, I would find it interesting that the library would allow:

  1. Allow the creation of different forms of cache persistence, so someone could create a plugin for react-native that uses async-storage, for example
  2. Add some configuration that allows the cache data to be returned when there is an error in the request
  3. Add some return attribute of object response (such as loading, error …) that informs you if the data in question is new or is a cached data
  4. Inform the time of the returned response. I think that’s possible, but I haven’t figured it out yet

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
alex-corycommented, Mar 7, 2020

I see what you’re saying. I like the idea of another cache policy. I will take a closer look at this as soon as I’m done with Suspense support.

I really appreciate this feedback!

In the meantime, feel free to poke around the library and submit a PR if you get to it before me!

Side note, I think I might still add the cache to the response because I think it might be useful for debugging purposes. What do you think?

1reaction
mogelbrodcommented, Mar 10, 2020

The cache-and-network policy would fit pretty well with this use case.

cacheLife could specify the TTL during which no additional network request needs to be made:

Cache strategy No cached data Fresh cache Expired cache (via cacheLife)
apollo cache-and-network loading + request cached + request (not supported)
use-http cache-first loading + request cached loading(?) + request
use-http cache-and-network (proposed) loading + request cached cached + request

Edit: Might be better to always return cached data via cachedData or similar, even if it is stale/expired. The behaviour above goes against the guarantee that cache-and-network always triggers a request:

However, regardless of whether or not the full data is in your cache this fetchPolicy will always execute query with the network interface…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Discussion with cache stale and network error #197 - GitHub
From what I understand from the documentation, when cachePolicy = cache-first and cacheLife > 0 , the cached data is returned if it...
Read more >
Prevent application and network instability by serving stale ...
stale -if-error tells a caching proxy that if an error is encountered while trying to talk to an origin server, a stale response...
Read more >
How Do I Fix My Caching Problems Or Clear Web Browser's ...
Close your browser and re-open it (make sure you are NOT on the cached page) and delete your temporary Internet files (clear your...
Read more >
Does no-cache allow a stale cached response to be returned?
The "no-cache" request directive indicates that a cache MUST NOT use a stored response to satisfy the request without successful validation on ...
Read more >
STALE data issue - TIBCO Community
This sounds like you're caching to Teradata. In this situation it's critical to ensure uninterrupted connectivity to your cache target during a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found