Angular library that enables developer accessible browser caching by providing a CacheService and a HttpCacheService.
This Angular library provides two services:
- CacheService: which interacts directly with the browser local/session storage
- HttpCacheService: which is a wrapper(decorator) around Angular HttpClient that offers the ability to cache any request that you want to (including post request) and offers the results as a Observable of the desired type, exactly as HttpClient.
To use this library you should have at least Angular 13. Installation of this library can be done using the following commands, depending on your package manager.
- npm:
npm i ngx-caching
- yarn
yarn add ngx-caching
The following is a basic usage example of the HttpCacheService:
...
import {HttpCacheService} from "ngx-caching";
...
constructor(private configService: ConfigService, private httpCached: HttpCacheService) { }
getValuesByType(typeId: number):Observable<any> {
return this.httpCached.get(this.configService.getPath('dictionary', 'entries', {typeId}));
}
In the above example, the values that will be retrieved will also be cached, so any subsequent subscription to this method will result in a cache look-up rather than another HTTP request.
- RxJS - Reactive Extensions Library for JavaScript
- Angular CLI - Angular command line interface
- Visual Studio Code - code editor
- @gabriel-rusu - Idea & Initial work