@dagonmetric/ng-cache
TypeScript icon, indicating that this package has built-in type declarations

2.1.2 • Public • Published

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.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.1.2
    67
    • latest

Version History

Package Sidebar

Install

npm i @dagonmetric/ng-cache

Weekly Downloads

67

Version

2.1.2

License

MIT

Unpacked Size

298 kB

Total Files

67

Last publish

Collaborators

  • mmzliveid
  • dagonmetric-contributor