Skip to content

Commit

Permalink
readme style updates; some clarifications
Browse files Browse the repository at this point in the history
  • Loading branch information
kurttheviking committed Dec 28, 2014
1 parent 901d673 commit 6ff8d1c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ bluecache
In-memory, read-through, Promises/A+, [lru-cache](https://github.com/isaacs/node-lru-cache) via [bluebird](https://github.com/petkaantonov/bluebird)


### Usage
## Usage

First, instantiate the cache, passing [options](https://github.com/kurttheviking/bluecache#options) if necessary.
First, instantiate the cache – passing [options](https://github.com/kurttheviking/bluecache#options) if necessary.

```
var BlueLRU = require("bluecache");
Expand All @@ -22,7 +22,7 @@ var options = {
var cache = BlueLRU(options);
```

Traditional LRU cache "getting" and "setting" takes place within a single call, promoting functional use. The `cache` instance is a Promise-returning function which takes two parameters: a String for the cache key and a Promise-returning function which resolves to the value to store in the cache. The cached value can be of any type.
Traditional cache "getting" and "setting" takes place within a single call, promoting functional use. The `cache` instance is a Promise-returning function which takes two parameters: a String for the cache key and a Promise-returning function which resolves to the value to store in the cache. The cached value can be of any type.

```
cache('key', function () {
Expand All @@ -34,7 +34,7 @@ cache('key', function () {
```


### Options
## Options

Options are passed directly to [lru-cache](https://github.com/isaacs/node-lru-cache#options) at instantiation

Expand All @@ -45,12 +45,12 @@ Options are passed directly to [lru-cache](https://github.com/isaacs/node-lru-ca
- `stale`: Allow the cache to return the stale (expired via `MaxAge`) value before deleting it


### Emitted events
## Emitted events

The cache instance is also an [event emitter](http://nodejs.org/api/events.html#events_class_events_eventemitter) which provides an `on` method against which the implementing application can listen for certain events.
The cache instance is also an [event emitter](http://nodejs.org/api/events.html#events_class_events_eventemitter) which provides an `on` method against which the implementing application can listen for the below events.


**cache:hit**
#### cache:hit

```
{
Expand All @@ -61,7 +61,7 @@ The cache instance is also an [event emitter](http://nodejs.org/api/events.html#
Note: `ms` is milliseconds elapsed between cache invocation and final resolution of the cached value.


**cache:miss**
#### cache:miss

```
{
Expand All @@ -72,21 +72,21 @@ Note: `ms` is milliseconds elapsed between cache invocation and final resolution
Note: `ms` is milliseconds elapsed between cache invocation and final resolution of the value function.


### API
## API

**cache(key, dataFunction)**
#### cache(key, dataFunction)

Attempts to get the current value of `key` from the cache. If the key exists, the "recently-used"-ness of the key is updated and the cached value is returned. If the key does not exist, the `dataFunction` is executed and the returned Promise resolved to its underlying value before being set in the cache and returned. (To support advanced cases, the key can also be a Promise for a String.)

A rejected promise is returned if either `key` or `dataFunction` are missing.
A rejected promise is returned if either `key` or `dataFunction` is missing.


**cache.del(key)**
#### cache.del(key)

Returns a promise that resolves to `undefined` after deleting `key` from the cache.


**cache.on(eventName, eventHandler)**
#### cache.on(eventName, eventHandler)

`eventName` is a string, corresponding to a [supported event](https://github.com/kurttheviking/bluecache#emitted-events). `eventHandler` is a function which responds to the data provided by the target event.

Expand All @@ -97,17 +97,17 @@ cache.on('cache:hit', function (data) {
```


**cache.reset()**
#### cache.reset()

Returns a promise that resolves to `undefined` after removing all data from the cache.


### Contribute
## Contribute

PRs are welcome! For bugs, please include a failing test which passes when your PR is applied.


### Release history
## Release history

The `0.1.x` versions focused on API parity with the underlying lru-cache. However, [Bluebird promisification](https://github.com/petkaantonov/bluebird/blob/master/API.md#promisification) makes that use case unnecessary (though perhaps a bit more complicated). The `0.2.x`+ versions refocus bluecache on implementing lru-cache as a more functionally-oriented, read-through, Promises/A+ module.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bluecache",
"description": "In-memory, read-through, Promises/A+, lru-cache",
"version": "0.2.0",
"version": "0.2.1",
"author": "kurttheviking <kurttheviking@outlook.com>",
"contributors": [
"kurttheviking <kurttheviking@outlook.com>"
Expand Down

0 comments on commit 6ff8d1c

Please sign in to comment.