angelnikolov / ts-cacheable

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

CacheBuster not working #44

Closed manojktechie closed 5 years ago

manojktechie commented 5 years ago

Hi,

I tried to implement Cacheable and CacheBuster. Cacheable is working fine but somehow CacheBuster is not working. Below is the code:

` import { Cacheable, CacheBuster } from 'ngx-cacheable'; const countryCacheBuster$ = new Subject();

@CacheBuster({ cacheBusterNotifier: countryCacheBuster$ }) public createCountry(country: Country): Observable { return this.http .post(${this.url}/api/createCountry, country, { withCredentials: true }); }

@Cacheable({ cacheBusterObserver: countryCacheBuster$ }) getCountrys(): Observable { return this.http.get(${this.url}/api/getCountryList) .pipe( catchError(error => error) ); } `

Where I am doing wrong ? Please help.

angelnikolov commented 5 years ago

Hmm, it should be working. How do you know that it isn't, what are you doing exactly?

manojktechie commented 5 years ago

It's not working because the results are not getting refreshed after creating records. It's picking the list from cache. In other words, I am calling getCountrys() after createCountry() to get the updated list but the api is not getting called. Instead it is returning the result from cache.

manojktechie commented 5 years ago

@angelnikolov it was my mistake. My API to create record was returning error and because of this Cachebuster was not working. Thank you for your help :)