In my app I use rxjs and I have a method that looks like this:
query<T extends TableRow>(queryString: string, silent = false): Observable<T[]> {
return this.sqliteService.dbQuery<T>(queryString).pipe(
tap(val => {
if (this.configService.debugMode && !silent) {
console.log(`\n${queryString}`);
console.log(val);
}
})
);
}
My query
method interlly calls dbQuery
that queries an sqlite database.
Also, the query
method is called many times in my app. So I'd like to globally cache the result whenever the queryString
is the same.
In other words, I'd like the query
method to avoid calling again dbQuery
when called with a queryString
parameter that has been called before, by returning the previously-cached value.
Not sure if this is relevant: my query
method lives in an Angular singleton service.