Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
sdvcrx committed Nov 3, 2017
1 parent 761312f commit 56209bf
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
45 changes: 45 additions & 0 deletions README.md
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
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"test": "mocha",
"test:watch": "mocha --watch"
},
"keywords": [],
"keywords": [
"cache",
"promise"
],
"author": "sdvcrx",
"license": "MIT",
"devDependencies": {
Expand Down

0 comments on commit 56209bf

Please sign in to comment.