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

docs: cache then refresh data #94

Open
leogouveia opened this issue Oct 30, 2023 · 0 comments
Open

docs: cache then refresh data #94

leogouveia opened this issue Oct 30, 2023 · 0 comments

Comments

@leogouveia
Copy link

I'm submitting a...

[x] Documentation issue or request

Current behavior

Cashew caches HTTP requests and only updates the cached data when it is deleted/expired.

Expected behavior

Cashew retrieves cached data, returns it to the user, and then makes an HTTP request to update the cached data. Once the updated data is available, Cashew pushes it to the user.

What is the motivation / use case for changing the behavior?

I am using @ngneat/cashew to cache HTTP requests in my Angular project.

I would like to know if it is possible to implement the cache and refresh strategy, as exemplified on the angular.io page link

I tried looking for information in the documentation and code, but I could not find any.

// cache-then-refresh
if (req.headers.get('x-refresh')) {
  const results$ = sendRequest(req, next, this.cache);
  return cachedResponse ?
    results$.pipe( startWith(cachedResponse) ) :
    results$;
}
// cache-or-fetch
return cachedResponse ?
  of(cachedResponse) : sendRequest(req, next, this.cache);

Environment


Angular version: 15.2.2


Browser:
- [x] Edge version 118
 
For Tooling issues:
- Node version: v18.17.0  
- Platform: Windows 

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

No branches or pull requests

1 participant