ngneat / cashew

🐿 A flexible and straightforward library that caches HTTP requests in Angular
https://www.netbasal.com
MIT License
682 stars 33 forks source link

Question: How to use with Headers? #11

Closed sanzwebdevelopment closed 4 years ago

sanzwebdevelopment commented 4 years ago

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[x] Support request
[ ] Other... Please describe:

Current behavior

I currently use a standard request to an API that needs Headers:

return this.http.get<ITideResults>(this.tideServiceURL, { headers: this.headers })

Expected behavior

Expected to be able to continue to use Headers as well as caching :-)

Minimal reproduction of the problem with instructions

Following the docs I tried:

return this.http.get<ITideResults>(this.tideServiceURL, { headers: this.headers }, withCache())

however realise get() expects 2 arguments and not 3. Not sure how to work out where to put withCache() if I'm also using headers.

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

The API I'm using has usage limits so I'd like to cache the request (for 7 days) on the users device on the first use so as to limit hitting the API ... Cashew seems to be a great option for this use case ;-)

Environment


Angular version: 9.1.0
@ngneat/cashew 1.1.4

Browser:
- [x ] Chrome (desktop) version 80.0.3987.163
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX

For Tooling issues:
- Node version: v12.13.0
- Platform:  Mac
NetanelBasal commented 4 years ago

this.http.get<ITideResults>(this.tideServiceURL, { ...withCache(), headers: this.headers })

sanzwebdevelopment commented 4 years ago

Awesome thanks mate :-) Works like a charm and caching perfectly. Love reading your articles ... just starting my Angular journey and learning so much :-)