cluster-cache
cache service to share data across workers/master
var cache = require('cluster-cache').use('cache-name', {
'persist': true,
'expire': 60000
});
var cache;
cache.keys({
'wait': 100
})
.then(function(keys){
});
listen({
'noWorkers': 1,
'createServer': require('http').createServer,
'app': app,
'port': 9090,
'monPort': 9091,
'debug': {
'webPort': 9092,
'saveLiveEdit': true
},
'ecv': {
'mode': 'control',
'root': '/ecv'
},
'cache': {
'enable': true,
'mode': 'standalone'
},
'heartbeatInterval': 5000
})
Note that, we allow you to use caching w/o cluster2, if you want to enable caching from none cluster2 runtime, the feature could be enabled via:
require('cluster-cache').enable();
get
- with the loader, if concurrent
get
happens across the workers in a cluster, only one will be allowed to load while the rest will be in fact watch
till that one finishes loading. - this will reduce the stress upon the backend services which loads exact same data nicely
var cache;
cache.get('cache-key-1',
function(){
return 'cache-value-loaded-1';
},
{
'wait': 100
})
.then(function(value){
},
function(error){
});
var cache;
cache.set('cache-key-1',
'cache-value-loaded-1',
{
'leaveIfNotNull': false,
'wait': 100
})
.then(function(happens){
},
function(error){
});
var cache;
cache.del('cache-key-1',
{
'wait': 100
})
.then(function(value){
});
var cache;
cache.watch('cache-key-1',
function watching(value, key){
});
var cache;
cache.unwatch('cache-key-1', watching);