-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,53 @@ | ||
# promise-cache-memorize # | ||
|
||
[![Build Status](https://travis-ci.org/sdvcrx/promise-cache.svg?branch=master)](https://travis-ci.org/sdvcrx/promise-cache) | ||
|
||
[![npm package](https://img.shields.io/npm/v/promise-cache-memorize.svg)](https://www.npmjs.com/package/promise-cache-memorize) | ||
|
||
Memoize promise-returning functions. | ||
|
||
## Usage ## | ||
|
||
#### promiseMemorize.remember(key, fn, maxAge) -> memorizedFn #### | ||
|
||
Memorize promise-returning functions `fn` with `key`. | ||
|
||
* **fn** - function that returning promise. | ||
* **key** - string using as cache key. | ||
* **maxAge** - (default: 0) cache expired after `maxAge` seconds. | ||
|
||
```javascript | ||
const promiseMemorize = require('promise-cache-memorize') | ||
const requestWithCache = promiseMemorize.remember('request', request) | ||
``` | ||
|
||
## Example ## | ||
|
||
```javascript | ||
const request = require('request-promise') | ||
const promiseMemorize = require('promise-cache-memorize') | ||
|
||
const requestWithCache = promiseMemorize.remember('request', request) | ||
|
||
function sendRequest () { | ||
return requestWithCache('http://httpbin.org/get') | ||
} | ||
|
||
sendRequest().then((res) => { | ||
console.log(res) | ||
|
||
// hit cache | ||
sendRequest().then((res) => { | ||
console.log(res) | ||
}) | ||
}) | ||
``` | ||
|
||
## TODO ## | ||
|
||
- [ ] Provide options for cache type | ||
- [ ] Multiple cache backend support | ||
|
||
## License ## | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters