easy-cache
Advanced tools
Comparing version 0.1.1 to 0.2.0
12
index.js
@@ -1,2 +0,2 @@ | ||
var EasyCache = module.exports = (function() { | ||
module.exports = (function() { | ||
@@ -7,3 +7,3 @@ var cache = {}; | ||
return new Date().getTime(); | ||
}; | ||
} | ||
@@ -21,3 +21,3 @@ return { | ||
if (typeof duration === 'number' && duration % 1 == 0) { | ||
if (typeof duration === 'number' && duration % 1 === 0) { | ||
newRecord.expire = duration + now(); | ||
@@ -39,3 +39,3 @@ newRecord.timeout = setTimeout(function() { | ||
throw new Error('Invalid key: ' + key); | ||
return null; | ||
}, | ||
@@ -54,6 +54,6 @@ | ||
unset: function(key) { | ||
delete(cache[key]); | ||
delete cache[key]; | ||
}, | ||
getSize: function() { | ||
size: function() { | ||
return Object.keys(cache).length; | ||
@@ -60,0 +60,0 @@ }, |
{ | ||
"name": "easy-cache", | ||
"description": "An easy way to handle in-memory key/value cache", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"repository": { | ||
@@ -11,2 +11,3 @@ "type": "git", | ||
"mocha": "~1.14.0", | ||
"jshint": "~2.3.0", | ||
"should": "~2.0.2" | ||
@@ -13,0 +14,0 @@ }, |
@@ -1,5 +0,3 @@ | ||
# easy-cache | ||
# easy-cache [![Build Status](https://secure.travis-ci.org/zonetti/easy-cache.png)](http://travis-ci.org/zonetti/easy-cache) | ||
[![Build Status](https://secure.travis-ci.org/zonetti/easy-cache.png)](http://travis-ci.org/zonetti/easy-cache) | ||
A simple NodeJS module to handle in-memory key/value cache. | ||
@@ -19,18 +17,14 @@ | ||
cache.set('foo', 'bar'); | ||
console.log(cache.get('foo')); // output: bar | ||
console.log(cache.getSize()); // output: 1 | ||
cache.unset('foo'); // remove specific record | ||
console.log(cache.get('foo')); // 'bar' | ||
console.log(cache.size()); // 1 | ||
cache.unset('foo'); | ||
console.log(cache.get('foo')); // null | ||
console.log(cache.size()); // 0 | ||
cache.set('temporary', 'value', 100); // duration in ms | ||
console.log(cache.get('temporary')); // output: value | ||
console.log(cache.get('temporary')); // 'value' | ||
console.log(cache.exists('temporary')); // true | ||
setTimeout(function() { | ||
try { | ||
console.log(cache.get('temporary')); // throws an exception | ||
} catch(err) { | ||
console.log(err.message); // Invalid key: temporary | ||
} | ||
}, 150); | ||
setTimeout(function() { | ||
console.log(cache.get('temporary')); // null | ||
if (!cache.exists('temporary')) { | ||
@@ -40,3 +34,3 @@ console.log('Key does not exist'); | ||
cache.clear(); // remove all records | ||
}, 200); | ||
}, 150); | ||
``` | ||
@@ -43,0 +37,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
5442
8
3
94
40