@dagonmetric/ng-cache
v2.1.2
Published
Caching service package for Angular applications.
Downloads
43
Readme
Caching Service for Angular
Caching service for Angular applications.
Get Started
Installation
npm
npm install @dagonmetric/ng-cache
or yarn
yarn add @dagonmetric/ng-cache
Module Setup (app.module.ts)
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
Usage (app.component.ts)
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
Samples
- Demo app view source / live edit in stackblitz
Build & Test Tools
We use lib-tools for bundling, testing and packaging our library projects.
Feedback and Contributing
Check out the Contributing page.
License
This repository is licensed with the MIT license.