0.0.19 • Published 4 years ago
ng-forage-cache v0.0.19
NgForageCache
This library was generated with Angular CLI version 8.2.14.
Install Dependencies
npm i localforage ngforage --save
npm i ng-forage-cache --save
How to use it
App module imports
Add NgForageCacheModule to your app imports
@NgModule({
imports: [
NgForageCacheModule
]
}
Using NgForageCacheService
Assuming that we have Country service,
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { NgForageCacheService } from 'ng-forage-cache';
export class CountryService {
baseUrl: string = "/api/Country/";
constructor(private httpClient: HttpClient, public cache:NgForageCacheService) { }
}
this a basic http request to get all countries as an array in an Observable
private getCountries(): Observable<Array<string>> {
let get$ = this.httpClient.get<string[]>(`${this.baseUrl}GetCountries`);
return get$;
}
Using NgForageCacheService
we can cache any Observable
result for any amount of time
cachedCountries(): Observable<Array<string>> {
//Cache an observable
let requestObservable = this.getCountries();
let cacheKey = "cachedCountries";
return this.cache.observable(cacheKey, requestObservable, 600); //cache results for 10 minutes
}
0.0.19
4 years ago
0.0.18
4 years ago
0.0.17
4 years ago
0.0.16
4 years ago
0.0.15
4 years ago
0.0.13
4 years ago
0.0.14
4 years ago
0.0.10
4 years ago
0.0.11
4 years ago
0.0.12
4 years ago
0.0.9
4 years ago
0.0.8
4 years ago
0.0.5
4 years ago
0.0.7
4 years ago
0.0.6
4 years ago
0.0.4
4 years ago
0.0.3
4 years ago
0.0.2
4 years ago
0.0.1
4 years ago