question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] Can I cache some api call with inner params ?

See original GitHub issue

Hi 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:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
angelnikolovcommented, Aug 16, 2019

@marcio199226 cacheBusterObserver: merge(cacheBusterSubject1, cacheBusterSubject2)

0reactions
angelnikolovcommented, Aug 16, 2019

It must be cacheBusterObserver: merge(cacheBusterSubject1.asObservable(), cacheBusterSubject2.asObservable()), sorry 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found