angelnikolov / ts-cacheable

Observable/Promise Cache Decorator
https://npmjs.com/package/ts-cacheable
ISC License
340 stars 42 forks source link

Does this work with subscribe? #119

Closed BD4vid777 closed 2 years ago

BD4vid777 commented 2 years ago

Hi there I can't get it work with such a GET request.

I even Made extra function for this in get method, but still nothing

@Cacheable({
    maxCacheCount: 1000,
    async: true,
  })
  getCacheable<T>(sUrl: string, params: any = null): Observable<T> {
    return this.svHttpClient.get<T>(sUrl, {params, headers: this.getHeadersAuthParm()});
  }
@Cacheable({
    maxCacheCount: 1000,
    async: true,
  })
  private getLegalBasisDict() {
    return this.getCacheable<DictionaryResponseModel>(environment.apiUrl + APP_SYSTEM.DICTIONARIES + FILTERS_DICTIONARY.LEGAL_BASIS)
      .pipe(
        map(response => response.result.wordsFromDictionary)
      )
      .subscribe((res: WordsFromDictionary[]) => {
        this._legalBasisDict = res.map(v => ({sValue: v.id, sText: v.groupNameFullName}))
        this._legalBasisDict$.next(this._legalBasisDict);
      })
  }
angelnikolov commented 2 years ago

@BD4vid777 Hey, what exactly isn't working? It looks fine to me? Do you have a Stackblitz with a repro?