dependencies Legend  Declarations  Module  Bootstrap  Providers  Exports cluster_HelgolandCachingModule cluster_HelgolandCachingModule_imports HelgolandCoreModule HelgolandCoreModule HelgolandCachingModule HelgolandCachingModule HelgolandCoreModule->HelgolandCachingModule

File

libs/caching/src/lib/caching.module.ts

Description

The caching module includes the following functionality:

  • caches similar requests

Methods

Static forRoot
forRoot(config: CacheConfig)
Parameters :
Name Type Optional
config CacheConfig No
import { ModuleWithProviders, NgModule } from '@angular/core';
import { HelgolandCoreModule, HTTP_SERVICE_INTERCEPTORS } from '@helgoland/core';

import { CacheConfig, CacheConfigService } from './config';
import { LocalHttpCacheInterval } from './get-data-cache/local-http-cache-interval';
import { LocalHttpCacheIntervalInterceptor } from './get-data-cache/local-http-cache-interval-interceptor';
import { CachingInterceptor } from './http-get-cache/cache-interceptor';
import { LocalHttpCache } from './http-get-cache/local-http-cache';
import { LocalOngoingHttpCache } from './http-get-cache/local-ongoing-http-cache';
import { HttpCache, HttpCacheInterval, OnGoingHttpCache } from './model';

const GET_DATA_CACHE_PROVIDERS = [
  {
    provide: HTTP_SERVICE_INTERCEPTORS,
    useClass: LocalHttpCacheIntervalInterceptor,
    multi: true
  },
  {
    provide: HttpCacheInterval,
    useClass: LocalHttpCacheInterval
  }
];

const HTTP_GET_PROVIDERS = [
  {
    provide: HttpCache,
    useClass: LocalHttpCache
  },
  {
    provide: HTTP_SERVICE_INTERCEPTORS,
    useClass: CachingInterceptor,
    multi: true
  },
  {
    provide: OnGoingHttpCache,
    useClass: LocalOngoingHttpCache
  }
];

/**
 * The caching module includes the following functionality:
 * - caches similar requests
 */
@NgModule({
  declarations: [],
  imports: [
    HelgolandCoreModule
  ],
  exports: [],
  providers: [HTTP_GET_PROVIDERS]
})
export class HelgolandCachingModule {

  static forRoot(config: CacheConfig): ModuleWithProviders {
    return {
      ngModule: HelgolandCachingModule,
      providers: [
        ...(config.getDataCacheActive ? GET_DATA_CACHE_PROVIDERS : []),
        {
          provide: CacheConfigService,
          useValue: config
        }
      ]
    };
  }

}

result-matching ""

    No results matching ""