This is a service to manager data in a cache service
$ npm install --save ng-data-cache
Inject NgDataCacheService into a component or service that you want to use.
import { Injectable } from '@angular/core';
import { NgDataCacheService } from 'ng-data-cache';
@Injectable({
providedIn: 'root'
})
export class MyService {
constructor(private cacheService: NgDataCacheService) { }
}
Must pass a key and a data to store.
this.cacheService.setData('MY_KEY', {name: 'Mario'});
Must pass the same key when was save.
this.cacheService.foundData('MY_KEY'); // {name: 'Mario'}
Must pass the same key when was save to remove data from cache.
this.cacheService.removeData('MY_KEY');
this.cacheService.cleanCache();
Function | Description |
---|---|
setData(id: string, data: any): void | Save data in cache in given key. |
removeData(id: string): void; | Remove data from given key. |
foundData(id: string): any; | Return data from given key. |
getCache(): DataCache[]; | Return all values stored in cache |
cleanCache(): void; | Clean all cache |