New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

cache-observable

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-observable

The cache decorator for connectable observable

latest
Source
npmnpm
Version
1.5.0
Version published
Maintainers
1
Created
Source

cache-observable

license npm

I created this decorator for cashing requests in my angular services.

Installation

npm i --save cache-observable

Usage

Need add @CacheObservable(ms) before a function that return ConnectableObservable (angular http.get() or Observable.ajax()), where ms is cache time in milliseconds.

Example

// book.service.ts

// ...
import CacheObservable from 'cache-observable';

@Injectable()
export class BookService {
  private path: string = '/books';

  constructor(private api: apiService) {
  }

  @CacheObservable(60 * 1000) // 1 min cache
  getBook(id: string): Observable<Book> {
    return this.api.get(`${this.path}/${id}`);
  }

  // ...
}

How it work

  • Call a function with @CacheObservable() decorator;
  • The Decorator lib check, if a storage have the observable entry then return it;
  • If the storage haven't a entry of a called function, then the Decorator lib create new entry in the storage;
  • The new entry observable has been chained with next functions:
  • publishReplay(1, ms) // publish one item for ms milliseconds
  • refCount() // check all subscribers
  • take(1) // take one
  • Return the entry.

License

MIT

Keywords

cache

FAQs

Package last updated on 28 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts