Skip to content

68ociredef/ng-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 

Repository files navigation

ng-cache

A cache system for Angular applications.

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 if 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 +1;
    }
    return item;
}

Configuration

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

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

 @NgModule({
    .....
  BzCacheModule.forRoot(
    {
      expirationTime: 2*60000
    }
  )
   
   ......

Demo

StackBlitz

Please give to repo a star ⭐.

About

Angular cache system

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published