У меня есть компонент, вызывающий такой сервис
this.service.GetCountries()
.subscribe((pCountries: ICountry[]) => {
this.mCountries = pCountries;
});`
мой сервис выглядит примерно так
private countriesCache$ = new ReplaySubject(1);
GetCountries(pForceRefresh?: boolean) {
if (!this.countriesCache$.observers.length || pForceRefresh) {
this.http.get<ICountry[]>(path + 'GetCountries')
.subscribe(
countries => {
this.countriesCache$.next(countries)
},
error => {
this.countriesCache$.error(error);
// Recreate the Observable as after Error we cannot emit data anymore
this.countriesCache$ = new ReplaySubject(1);
}
);
}
return this.countriesCache$;
}
Как видите, я кэширую результат и возвращаю кэшированные данныена каждый последующий запрос.
Есть ли способ, которым я могу переместить эту логику кэширования в декоратор?Я не могу найти какие-либо примеры этого онлайн, кроме этого пакета