Skip to content

docs: cache then refresh data #94

@leogouveia

Description

@leogouveia

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 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions