Evan Lucas
MIT
$ npm install --save clache$ npm test$ npm run coverContructor
Example
var opts = {
ttl: 100 // in seconds
, host: '127.0.0.1'
, port: 6379
, password: null
}
var cache = new clache(opts)| Name | Type(s) | Description |
|---|---|---|
| opts | Object | The options object |
Wrap an asynchronous function and cache it
Example
function find(cb) {
return cb(null, { id: 1, name: 'evan' })
}
var id = '1234'
clache.wrap('user_'+id, find, function(err, results) {
if (err) throw err
console.log(results)
})| Name | Type(s) | Description |
|---|---|---|
| key | String | The key |
| work | Function | The work function |
| cb | Function | function(err, res) |
Set val for the given key
| Name | Type(s) | Description |
|---|---|---|
| key | String | The key |
| val | String, Number, Boolean, Array, Object | The value |
| cb | Function | function(err, res) |
Set val for the given key with ttl
| Name | Type(s) | Description |
|---|---|---|
| key | String | The key |
| ttl | Number | The ttl |
| val | String, Number, Boolean, Array, Object | The value |
| cb | Function | function(err, res) |
Get the value for the given key
| Name | Type(s) | Description |
|---|---|---|
| key | String | The key |
| cb | Function | function(err, res) |
Deletes the value for the given key
| Name | Type(s) | Description |
|---|---|---|
| key | String | The key |
| cb | Function | function(err, res) |

