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

Usage questions offline mode #2

Closed
fvisticot opened this issue Jul 28, 2019 · 4 comments
Closed

Usage questions offline mode #2

fvisticot opened this issue Jul 28, 2019 · 4 comments
Labels
documentation Improvements or additions to documentation

Comments

@fvisticot
Copy link

Can you please detail in the documentation how is managed the case when no network is available ? Is there an error or the data is returned by the cache ?

@hurshi
Copy link
Owner

hurshi commented Jul 28, 2019

Hi, fvisticot

Thanks for your questions.
I have written an example in README, please let me know if you still have confusion.

Example for maxAge and maxStale

_dio.post(
	"https://www.exmaple.com",
	data: {'k': "keyword"},
	options:buildCacheOptions(
  		Duration(days: 3), 
  		maxStale: Duration(days: 7), 
	)
)
  1. 0 ~ 3 days : Return data from cache directly (irrelevant with network).
  2. 3 ~ 7 days:
    1. Get data from network first.
    2. If getting data from network succeeds, refresh cache.
    3. If getting data from network fails or no network avaliable, get data from cache instead of an error.
  3. 7 ~ ∞ days: It won't use cache anymore, and the cache will be deleted at the right time.

@JCKodel
Copy link

JCKodel commented Aug 3, 2019

@hurshi

Scenario:
When online, read always from network and cache result.
When offline, read from cache.

Code:
buildCacheOptions(Duration.zero, maxStale: Duration(days: 30))

Is this right?

@hurshi
Copy link
Owner

hurshi commented Aug 5, 2019

@JCKodel Yes, that's right.

@hurshi hurshi added the documentation Improvements or additions to documentation label Aug 6, 2019
@hurshi hurshi closed this as completed Aug 9, 2019
@IhwanID
Copy link

IhwanID commented Jun 10, 2020

Hi @hurshi

how if the scenario is I want to save to the cache in the first call network only, after that the app always read from the cache when online & offline?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants