angularjs-promise-cache

![GitHub](https://img.shields.io/github/license/AndrewLawendy/angularjs-promise-cache) ![GitHub package.json version](https://img.shields.io/github/package-json/v/AndrewLawendy/angularjs-promise-cache) ![npm](https://img.shields.io/npm/dw/angularjs-promis


Keywords
angular, angualrjs, promise, cache, angularjs, caching, memoization, promises
License
MIT
Install
npm install angularjs-promise-cache@1.1.2

Documentation

angular-request-dedup

This library aims to deduplicate repetitive call to the server while the request is still pending and pass the same promise to callers.

GitHub GitHub package.json version npm GitHub file size in bytes

NPM

When to use it

Almost always.

Say you have a button that calls the server then process the response and does something, but then the user -or any other scenario- clicked the button three times, that's three calls to server to do the same thing.

Our service can provide caching the promise and dispatching the same promise to all three calls.

How to use

npm i angular-request-dedup

Integrate in the angular app angular.module("app", ["angular-request-dedup"])

Example

class MainResource {
    constructor(AngularRequestDedup) {
        this.AngularRequestDedup = AngularRequestDedup;
    }

    getAll(params) {
        return this.AngularRequestDedup.dedup(url).get(params)
    }
}

Highlights

  1. Once the promise is resolved, the promise is discarded from the cache.
  2. You can pass isPersistent flag in the params object to keep the promise in the app state.

Prerequisites

  • It works with minium of AngualrJs 1.5.x
  • Any bundler would do, no need for special loaders