Discussion with cache stale and network error
See original GitHub issueFrom 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:
- Allow the creation of different forms of cache persistence, so someone could create a plugin for react-native that uses
async-storage
, for example - Add some configuration that allows the cache data to be returned when there is an error in the request
- 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 - Inform the time of the returned response. I think that’s possible, but I haven’t figured it out yet
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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?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:cacheLife
)cache-and-network
cache-first
cache-and-network
(proposed)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 thatcache-and-network
always triggers a request: