Skip to content

Commit

Permalink
- added option to disable check period
Browse files Browse the repository at this point in the history
- update read me
- update package-version
  • Loading branch information
tcs-de committed May 14, 2012
1 parent 176541d commit ba6e722
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 7 deletions.
41 changes: 41 additions & 0 deletions README.md
Expand Up @@ -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 )`
Expand Down Expand Up @@ -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()`
Expand Down
2 changes: 1 addition & 1 deletion lib/node_cache.coffee
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/node_cache.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions test/node_cache-test.coffee
Expand Up @@ -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 ) ->
Expand Down
4 changes: 2 additions & 2 deletions test/node_cache-test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ba6e722

Please sign in to comment.