Skip to content

Commit 7dcae80

Browse files
committed
fixed getValLength for null values; this fixes #151; also added a test-case
1 parent 5bd38ea commit 7dcae80

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

_src/lib/node_cache.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ module.exports = class NodeCache extends EventEmitter
593593
# if the data is a Promise, use defined default
594594
# (can't calculate actual/resolved value size synchronously)
595595
@options.promiseValueSize
596-
else if typeof value is "object"
596+
else if value? and typeof value is "object"
597597
# if the data is an Object multiply each element with a defined default length
598598
@options.objectValueSize * Object.keys( value ).length
599599
else if typeof value is "boolean"

_src/test/mocha_test.coffee

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,4 +1143,24 @@ describe "`#{pkg.name}@#{pkg.version}` on `node@#{process.version}`", () ->
11431143

11441144
return
11451145

1146+
describe "Issues", () ->
1147+
describe("#151 - cannot set null", () ->
1148+
cache = null
1149+
before(() ->
1150+
cache = new nodeCache()
1151+
return
1152+
)
1153+
1154+
it("set the value `null` - this should not throw or otherwise fail", () ->
1155+
cache.set("test", null)
1156+
return
1157+
)
1158+
1159+
it("should also return `null`", () ->
1160+
should(cache.get("test")).be.null()
1161+
return
1162+
)
1163+
return
1164+
)
1165+
return
11461166
return

0 commit comments

Comments
 (0)