Permalink
Browse files

- added option to disable check period

- update read me
- update package-version
  • Loading branch information...
1 parent 176541d commit ba6e722df0eb21531c69cbb4d35bc7ed925396a3 @tcs-de tcs-de committed May 14, 2012
Showing with 48 additions and 7 deletions.
  1. +41 −0 README.md
  2. +1 −1 lib/node_cache.coffee
  3. +1 −1 lib/node_cache.js
  4. +1 −1 package.json
  5. +2 −2 test/node_cache-test.coffee
  6. +2 −2 test/node_cache-test.js
View
41 README.md
@@ -23,6 +23,16 @@ var NodeCache = require( "node-cache" );
var myCache = new NodeCache();
```
+### Options
+
+- `stdTTL`: the standard ttl as number in seconds for every generated cache element. Default = 0 = unlimited
+- `checkperiod`: The period in seconds as number for the automatc delete check intervall. 0 = no periodic check
+
+```
+var NodeCache = require( "node-cache" );
+var myCacheOptions = new NodeCache( { stdTTL: 100, checkperiod: 120 } );
+```
+
### Store a key (SET):
`myCache.set( key, val, [ ttl ], callback )`
@@ -112,6 +122,37 @@ myCache.del( [ "myKeyA", "myKeyB" ], function( err, count ){
});
```
+### Change TTL
+
+`myCache.ttl( key, ttl, callback )`
+
+Redefine the ttl of a key. Returns true if the key has been found and changed. Otherwise returns false.
+If the ttl-argument isnt passed the default-TTL will be used.
+
+```
+myCache = new NodeCache( { stdTTL: 100 } )
+myCache.ttl( "existendKey", 100, function( err, changed ){
+ if( !err ){
+ console.log( changed ); // true
+ // ... do something ...
+ }
+});
+
+myCache.ttl( "missingKey", 100, function( err, changed ){
+ if( !err ){
+ console.log( changed ); // false
+ // ... do something ...
+ }
+});
+
+myCache.ttl( "existendKey", function( err, changed ){
+ if( !err ){
+ console.log( changed ); // true
+ // ... do something ...
+ }
+});
+```
+
### Statistics
`myCache.getStats()`
View
2 lib/node_cache.coffee
@@ -279,7 +279,7 @@ module.exports = class NodeCache
for key, value of @data
@_check( key, value )
- if startPeriod
+ if startPeriod and @options.checkperiod > 0
@checkTimeout = setTimeout( @_checkData, ( @options.checkperiod * 1000 ) )
return
View
2 lib/node_cache.js
@@ -157,7 +157,7 @@
value = _ref[key];
this._check(key, value);
}
- if (startPeriod) {
+ if (startPeriod && this.options.checkperiod > 0) {
this.checkTimeout = setTimeout(this._checkData, this.options.checkperiod * 1000);
}
};
View
2 package.json
@@ -2,7 +2,7 @@
"name": "node-cache",
"description": "Simple and fast NodeJS internal caching.",
"keywords": [ "cache", "caching", "local", "variable", "coffee", "coffee-script", "underscore", "multi" ],
- "version": "0.2.0",
+ "version": "0.3.0",
"author": "tcs-de <github@tcs.de>",
"main": "./index.js",
"homepage": "https://github.com/tcs-de/nodecache",
View
4 test/node_cache-test.coffee
@@ -3,10 +3,10 @@ _ = require( "underscore" )
VCache = require "../lib/node_cache"
localCache = new VCache( stdTTL: 0 )
-localCacheTTL = new VCache( stdTTL: 0.3 )
+localCacheTTL = new VCache( stdTTL: 0.3, checkperiod: 0 )
# just for testing disable the check period
localCache._killCheckPeriod()
-localCacheTTL._killCheckPeriod()
+#localCacheTTL._killCheckPeriod() # disabled to test checkperiod = 0
# test helper
randomString = ( length, withnumbers = true ) ->
View
4 test/node_cache-test.js
@@ -6,10 +6,10 @@
stdTTL: 0
});
localCacheTTL = new VCache({
- stdTTL: 0.3
+ stdTTL: 0.3,
+ checkperiod: 0
});
localCache._killCheckPeriod();
- localCacheTTL._killCheckPeriod();
randomString = function(length, withnumbers) {
var chars, i, randomstring, rnum, string_length;
if (withnumbers == null) {

0 comments on commit ba6e722

Please sign in to comment.