node-cache
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -6,4 +6,4 @@ (function() { | ||
exports.version = '3.0.1'; | ||
exports.version = '3.1.0'; | ||
}).call(this); |
@@ -19,2 +19,3 @@ (function() { | ||
this.options = options != null ? options : {}; | ||
this._initErrors = bind(this._initErrors, this); | ||
this._error = bind(this._error, this); | ||
@@ -34,2 +35,3 @@ this._getValLength = bind(this._getValLength, this); | ||
this.get = bind(this.get, this); | ||
this._initErrors(); | ||
this.data = {}; | ||
@@ -42,3 +44,4 @@ this.options = _.extend({ | ||
checkperiod: 600, | ||
useClones: true | ||
useClones: true, | ||
errorOnMissing: false | ||
}, this.options); | ||
@@ -53,6 +56,11 @@ this.stats = { | ||
this._checkData(); | ||
return; | ||
} | ||
NodeCache.prototype.get = function(key, cb) { | ||
var _ret; | ||
NodeCache.prototype.get = function(key, cb, errorOnMissing) { | ||
var _err, _ret; | ||
if (typeof cb === "boolean" && arguments.length === 2) { | ||
errorOnMissing = cb; | ||
cb = void 0; | ||
} | ||
if ((this.data[key] != null) && this._check(key, this.data[key])) { | ||
@@ -67,4 +75,14 @@ this.stats.hits++; | ||
this.stats.misses++; | ||
if (cb != null) { | ||
cb(null, void 0); | ||
if (this.options.errorOnMissing || errorOnMissing) { | ||
_err = this._error("ENOTFOUND", { | ||
key: key | ||
}, cb); | ||
if (_err != null) { | ||
throw _err; | ||
} | ||
return; | ||
} else { | ||
if (cb != null) { | ||
cb(null, void 0); | ||
} | ||
} | ||
@@ -332,3 +350,3 @@ return void 0; | ||
error.errorcode = type; | ||
error.msg = this._ERRORS[type] || "-"; | ||
error.message = this.ERRORS[type] != null ? this.ERRORS[type](data) : "-"; | ||
error.data = data; | ||
@@ -342,4 +360,14 @@ if (cb && _.isFunction(cb)) { | ||
NodeCache.prototype._initErrors = function() { | ||
var _errMsg, _errT, ref; | ||
this.ERRORS = {}; | ||
ref = this._ERRORS; | ||
for (_errT in ref) { | ||
_errMsg = ref[_errT]; | ||
this.ERRORS[_errT] = _.template(_errMsg); | ||
} | ||
}; | ||
NodeCache.prototype._ERRORS = { | ||
"ENOTFOUND": "Key not found", | ||
"ENOTFOUND": "Key `<%= key %>` not found", | ||
"EKEYSTYPE": "The keys argument has to be an array." | ||
@@ -346,0 +374,0 @@ }; |
@@ -6,3 +6,3 @@ { | ||
"tags": [ "cache", "caching", "local", "variable", "multi", "memory", "internal", "node", "memcached", "object" ], | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"author": "tcs-de <github@tcs.de>", | ||
@@ -9,0 +9,0 @@ "main": "./index.js", |
@@ -41,2 +41,3 @@ node-cache | ||
`0` = no periodic check. | ||
- `errorOnMissing`: *(default: `false`)* en/disable throwing or passing an error to the callback if attempting to `.get` a missing or expired value. | ||
- `useClones`: *(default: `true`)* en/disable cloning of variables. If `true` you'll get a copy of the cached variable. If `false` you'll save and get just the reference. | ||
@@ -113,9 +114,20 @@ **Note:** `true` is recommended, because it'll behave like a server-based caching. You should set `false` if you want to save complex variable types like functions, promises, regexp, ... | ||
The return format changed to the simple value and a `ENOTFOUND` error if not found *( as `callback( err )` or on sync call as result instance of `Error` )*. | ||
The return format changed to a simple value and a `ENOTFOUND` error if not found *( as `callback( err )` or on sync call as result instance of `Error` )*. | ||
**Since `2.1.0`**: | ||
The return format changed to the simple value, but a due to discussion in #11 a miss shouldn't return an error. | ||
So until 2.1.0 it'll return a `undefined`. | ||
The return format changed to a simple value, but a due to discussion in #11 a miss shouldn't return an error. | ||
So after 2.1.0 a miss returns `undefined`. | ||
**Since `3.1.0`** | ||
`errorOnMissing` option added | ||
```js | ||
try{ | ||
value = myCache.get( "not-existing-key", true ); | ||
} catch( err ){ | ||
// ENOTFOUND: Key `not-existing-key` not found | ||
} | ||
``` | ||
## Get multiple keys (MGET): | ||
@@ -444,4 +456,18 @@ | ||
SET: `238`ms ( `4.06`µs per item ) | ||
GET: `34`ms ( `0.67`µs per item ) | ||
GET: `34`ms ( `0.67`µs per item ) | ||
### Version 3.1.x | ||
**node.js `v0.10.41`** | ||
SET: `305ms` ( 3.05µs per item ) | ||
GET: `104ms` ( 1.04µs per item ) | ||
**node.js `v0.12.9`** | ||
SET: `337ms` ( 3.37µs per item ) | ||
GET: `167ms` ( 1.67µs per item ) | ||
**node.js `v4.2.6`** | ||
SET: `356ms` ( 3.56µs per item ) | ||
GET: `83ms` ( 0.83µs per item ) | ||
> until the version 3.0.x the object cloning is included, so we lost a little bit of the performance | ||
@@ -452,2 +478,3 @@ | ||
|:--:|:--:|:--| | ||
|3.1.0|2016-01-29|Added option `errorOnMissing` to throw/callback an error o a miss during a `.get( "key" )`. Thanks to [David Godfrey](https://github.com/david-byng) for the pull [#45](https://github.com/tcs-de/nodecache/pull/45). Added docker files and a script to run test on different node versions locally| | ||
|3.0.1|2016-01-13|Added `.unref()` to the checkTimeout so until node `0.10` it's not necessary to call `.close()` when your script is done. Thanks to [Doug Moscrop](https://github.com/dougmoscrop) for the pull [#44](https://github.com/tcs-de/nodecache/pull/44).| | ||
@@ -476,6 +503,14 @@ |3.0.0|2015-05-29|Return a cloned version of the cached element and save a cloned version of a variable. This can be disabled by setting the option `useClones:false`. (Thanks for #27 to [cheshirecatalyst](https://github.com/cheshirecatalyst) and for #30 to [Matthieu Sieben](https://github.com/matthieusieben))| | ||
|[**rsmq**](https://github.com/smrchy/rsmq)|A really simple message queue based on redis| | ||
|[**redis-heartbeat**](https://github.com/mpneuried/redis-heartbeat)|Pulse a heartbeat to redis. This can be used to detach or attach servers to nginx or similar problems.| | ||
|[**systemhealth**](https://github.com/mpneuried/systemhealth)|Node module to run simple custom checks for your machine or it's connections. It will use [redis-heartbeat](https://github.com/mpneuried/redis-heartbeat) to send the current state to redis.| | ||
|[**rsmq-cli**](https://github.com/mpneuried/rsmq-cli)|a terminal client for rsmq| | ||
|[**rest-rsmq**](https://github.com/smrchy/rest-rsmq)|REST interface for.| | ||
|[**redis-sessions**](https://github.com/smrchy/redis-sessions)|An advanced session store for NodeJS and Redis| | ||
|[**connect-redis-sessions**](https://github.com/mpneuried/connect-redis-sessions)|A connect or express middleware to simply use the [redis sessions](https://github.com/smrchy/redis-sessions). With [redis sessions](https://github.com/smrchy/redis-sessions) you can handle multiple sessions per user_id.| | ||
|[**redis-heartbeat**](https://github.com/mpneuried/redis-heartbeat)|Pulse a heartbeat to redis. This can be used to detach or attach servers to nginx or similar problems.| | ||
|[**systemhealth**](https://github.com/mpneuried/systemhealth)|Node module to run simple custom checks for your machine or it's connections. It will use [redis-heartbeat](https://github.com/mpneuried/redis-heartbeat) to send the current state to redis.| | ||
|[**redis-notifications**](https://github.com/mpneuried/redis-notifications)|A redis based notification engine. It implements the rsmq-worker to safely create notifications and recurring reports.| | ||
|[**nsq-logger**](https://github.com/mpneuried/nsq-logger)|Nsq service to read messages from all topics listed within a list of nsqlookupd services.| | ||
|[**nsq-topics**](https://github.com/mpneuried/nsq-topics)|Nsq helper to poll a nsqlookupd service for all it's topics and mirror it locally.| | ||
|[**nsq-nodes**](https://github.com/mpneuried/nsq-nodes)|Nsq helper to poll a nsqlookupd service for all it's nodes and mirror it locally.| | ||
|[**nsq-watch**](https://github.com/mpneuried/nsq-watch)|Watch one or many topics for unprocessed messages.| | ||
|[**hyperrequest**](https://github.com/mpneuried/hyperrequest)|A wrapper around [hyperquest](https://github.com/substack/hyperquest) to handle the results| | ||
|[**task-queue-worker**](https://github.com/smrchy/task-queue-worker)|A powerful tool for background processing of tasks that are run by making standard http requests | ||
@@ -485,4 +520,5 @@ |[**soyer**](https://github.com/mpneuried/soyer)|Soyer is small lib for server side use of Google Closure Templates with node.js.| | ||
|[**backlunr**](https://github.com/mpneuried/backlunr)|A solution to bring Backbone Collections together with the browser fulltext search engine Lunr.js| | ||
|[**domel**](https://github.com/mpneuried/domel)|A simple dom helper if you want to get rid of jQuery| | ||
|[**obj-schema**](https://github.com/mpneuried/obj-schema)|Simple module to validate an object by a predefined schema| | ||
# The MIT License (MIT) | ||
@@ -489,0 +525,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
540
32370
8
473