2.0.0 • Published 9 years ago

memorize-promise v2.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

memorize-promise Build Status

Save promise result and update it from time to time.

Install

$ npm install --save memorize-promise

Usage

const got = require('got');
const memorizePromise = require('memorize-promise');

const cache = memorizePromise(() => got('google.com'));

cache.then(res => console.log(res.body)); // Content 1
cache.then(res => console.log(res.body)); // Content 1

setTimeout(function () {
	cache.then(res => console.log(res.body)); // Content 2
	cache.then(res => console.log(res.body)); // Content 2

	cache.stop(); // Stops updates
}, 5005);

API

memorizePromise(func, options)

func

Type: Function

Factory of promises. It will be called for new promise with data every updateInterval milliseconds.

options

updateInterval

Type: Number
Default: 5000

Update interval in milliseconds.

ttl

Type: Number
Default: 60000

Lifetime of update timeout after last hit.

License

MIT © Vsevolod Strukchinsky

2.0.0

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago