Skip to content

Commit

Permalink
chore: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
sdvcrx committed Dec 20, 2017
1 parent 4e382f2 commit ab08a3f
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,47 @@
# 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 ####
```javascript
const Cache = require('promise-cache-memorize')('redis')

const requestWithCache = Cache.remember('request', request)
```

### cacheFactory(type, options) -> Cache ###

Factory function that configuring and returning actual `Cache` object.

* **type** - cache backend. Current support `simple` , `lru` or `redis`

* **options** - cache backend configuration.

* **timeout** - (default: 3600) cache expire timeout, 1 hour by default


* if it is [redis](https://github.com/luin/ioredis) backend, see [ioredis document](https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options)
* if it is [lru](https://github.com/isaacs/node-lru-cache) backend, see [lru document](https://github.com/isaacs/node-lru-cache#options)

#### Cache.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)
```
* **maxAge** - (default: options.timeout) cache expired after `maxAge` seconds.

## Example ##

```javascript
const request = require('request-promise')
const promiseMemorize = require('promise-cache-memorize')
const Cache = require('promise-cache-memorize')('redis')

const requestWithCache = promiseMemorize.remember('request', request)
const requestWithCache = Cache.remember('request', request)

function sendRequest () {
return requestWithCache('http://httpbin.org/get')
Expand All @@ -45,9 +59,9 @@ sendRequest().then((res) => {

## TODO ##

- [ ] Provide options for cache type
- [ ] Multiple cache backend support
- [x] Provide options for cache type
- [x] Multiple cache backend support

## License ##

MIT
MIT

0 comments on commit ab08a3f

Please sign in to comment.