[Question] Can I cache some api call with inner params ?
See original GitHub issueHi I will explain my question with simple example:
@Cacheable({
maxAge: 60000,
maxCacheCount: 10,
cacheBusterObserver: entityBustCache$.asObservable()
})
list(payload: any = {}): Observable<any> {
return this._http.post('${environment.baseUrl}/some/api', { ...payload, inner_param: this._someService.getObservable().value });
}
So my question is how can I cache some endpoints with inner params that are not provided by method call? I have tried to cache internal closure with all params but without success
list(payload: any = {}): Observable<any> {
payload = { inner_param: this._someService.getObservable().value, ...payload };
@Cacheable({
maxAge: 60000,
maxCacheCount: 10,
cacheBusterObserver: entityBustCache$.asObservable()
})
const apiCall = (p) => this._http.post('${environment.baseUrl}/some/api', p)
return apiCall(payload);
}
Or I have to move all params to method definition in in my case:
list(payload: any = {}, inner_param): Observable<any> {
// code
}
Best regards and thanks for this awesome library !
P.S I think that decorators can only decorates methods/properties of class, so maybe we could add an additional param to Cacheable decorator something like this:
@Cacheable({
parameters: {}
})
And merge this option before this line https://github.com/angelnikolov/ngx-cacheable/blob/master/cacheable.decorator.ts#L43? Do you think it could work?
RE P.S
Seems that something like this is working properly:
list(payload: any = {}): Observable<any> {
payload = { ...payload, inner_param: this._someService.getObservable().value };
return this._listEntity(payload);
}
@Cacheable({
maxAge: 60000,
maxCacheCount: 10,
cacheBusterObserver: BustCache$.asObservable()
})
private _listEntity(payload: any = {}): Observable<any> {
return this._http.post(`${environment.baseUrl}/some/api`, payload);
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
REST API Best practices: Where to put parameters? [closed]
My question comes from the fact that generally, intermediary HTTP components don't cache responses of requests that contains a query string. So, it...
Read more >REST API Design Best Practices for Parameter and Query ...
I've always stuck with GET does not modify and is therefore cacheable by any layer in the between the client and the server...
Read more >Cache.match() - Web APIs - MDN Web Docs
A Promise that resolves to the first Response that matches the request or to undefined if no match is found. Note: Cache.match() is...
Read more >Caching External API Requests - Real Python
Learn how to to cache external API calls in your Python apps with the excellent "requests" module. This tutorial includes a full example...
Read more >Api Gateway cache key parameters - method level vs ...
API Gateway can cache the method's responses, depending on the parameter values used." So where you define the cache key will determine at...
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 FreeTop 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
Top GitHub Comments
@marcio199226
cacheBusterObserver: merge(cacheBusterSubject1, cacheBusterSubject2)
It must be
cacheBusterObserver: merge(cacheBusterSubject1.asObservable(), cacheBusterSubject2.asObservable())
, sorry 😃