1.1.1 • Published 1 month ago

ng-cache v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

ng-cache

A cache system for Angular application.

Getting started

Install ng-cache

npm install ng-cache

Usage

import {ngCache } from 'ng-cache';
...
 //Http request
@ngCache()
public getUsers() {
    return this.http.get<User[]>('user')
}

//Value is stored in session storage if set a key
@ngCache('user')
public getUsers() {
    return this.http.get<User[]>('user')
}

//Dynamic composit key.
@ngCache('user{}') //key = user1 id id=1;
public getUserById(id: number) {
    return this.http.get<User>('user/'+ id)
}

//Sync method
@ngCache()
public method() {
    console.log("Call method")
    const length = 50000000;
    let item = 0;
    for(let index=0; index < length; index++) {
       item = item + 2;
    }
    return item;
}

Configuration

 //Local configuration.
 @ngCache(null, {expirationTime: 2*60000}) // in milliseconds

 //If you want the data is cached in local storage and not in session one
 @ngCache("user", {isInLocalStorage: true})

 //Global configuration.
 import {BzCacheModule} from 'ng-cache';

 @NgModule({
    .....
  BzCacheModule.forRoot(
    {
      expirationTime: 2*60000,
      isInLocalStorage: true //If you want the data is cached in local storage and not in session one
    }
  )
   
   ......

Demo

StackBlitz

Please give to repo a star :star:.

1.1.1

1 month ago

1.1.0

1 month ago

1.0.8

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.0

2 years ago