Skip to content

DagonMetric/ng-cache

Folders and files

NameName
Last commit message
Last commit date
Jan 3, 2021
Jun 19, 2020
Jan 3, 2021
Jan 3, 2021
Feb 25, 2021
Jan 6, 2020
Jun 25, 2020
Jan 5, 2021
Jun 25, 2020
Jun 19, 2020
Jan 6, 2020
Jan 6, 2020
Nov 1, 2020
Jan 3, 2021
Jan 3, 2021
Mar 1, 2021
Mar 1, 2021
Jan 3, 2021
Jun 25, 2020
Jan 3, 2021

Repository files navigation

Caching Service for Angular

GitHub Actions Status Azure Pipelines Status Gitter

Caching service for Angular applications.

Get Started

Installation

npm

npm install @dagonmetric/ng-cache

or yarn

yarn add @dagonmetric/ng-cache

Latest npm package is npm version

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

Build & Test Tools

We use lib-tools for bundling, testing and packaging our library projects.

Lib Tools

Feedback and Contributing

Check out the Contributing page.

License

This repository is licensed with the MIT license.