Caching service for Angular applications.
npm
npm install @dagonmetric/ng-cache
or yarn
yarn add @dagonmetric/ng-cache
import { CacheLocalStorageModule, CacheModule, MemoryCacheModule } from '@dagonmetric/ng-cache';
@NgModule({
imports: [
// Other module imports
// ng-cache modules
CacheModule,
CacheLocalStorageModule,
MemoryCacheModule
]
})
export class AppModule { }
Live edit app.module.ts in stackblitz
import { HttpClient } from '@angular/common/http';
import { Component, ViewEncapsulation } from '@angular/core';
import { Observable } from 'rxjs';
import { CacheService } from '@dagonmetric/ng-cache';
export interface AppOptions {
name: string;
lang: string;
logEnabled: boolean;
logLevel: number;
num: number;
arr: string[];
child: {
key1: string;
key2: boolean;
};
}
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
appOptions$: Observable<AppOptions>;
constructor(private readonly cacheService: CacheService, private readonly httpClient: HttpClient) {
this.appOptions$ = this.cacheService.getOrSet('configuration', () => {
return this.httpClient.get<AppOptions>(
'https://us-central1-ng-config-demo.cloudfunctions.net/configuration'
);
});
}
}
Live edit app.component.ts in stackblitz
- Demo app view source / live edit in stackblitz
We use lib-tools for bundling, testing and packaging our library projects.
Check out the Contributing page.
This repository is licensed with the MIT license.