Skip to content

Commit

Permalink
Added memcached
Browse files Browse the repository at this point in the history
  • Loading branch information
zerious committed Jun 10, 2014
1 parent bbebaf3 commit b5143fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion lib/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ var fs = require('fs');
var os = require('os');
var cluster = require('cluster');

// Module dependencies.
var Memcached = require('memcached');

// TODO: Determine whether this works on more than just Mac OS.
var bold = '\u001b[1m';
var normal = '\u001b[22m';
Expand All @@ -13,7 +16,7 @@ var yellow = '\u001b[33m';
var white = '\u001b[37m';
var blue = '\u001b[34m';

// Module dependencies.
// Internal dependencies.
var Class = require('./Class');

// Decorate http request and response prototypes.
Expand Down Expand Up @@ -61,10 +64,12 @@ module.exports = Class.extend({
publics: ['public'],
scripts: {'/all.js': ['scripts']},
styles: {'/all.css': ['styles']},
cache: null,
logger: null,
logLevel: (env == 'prod' ? 'info' : (env == 'dev' ? 'debug' : 'trace')),
asciiArt: null,
cullEnv: env,
enableCache: true,
enableChug: true,
enableD6: true,
enableBeams: true,
Expand Down Expand Up @@ -112,6 +117,10 @@ module.exports = Class.extend({
if (app.config.enableChug) {
app.initChug();
}

if (app.config.enableCache) {
app.initCache();
}
}
},

Expand Down Expand Up @@ -149,6 +158,16 @@ module.exports = Class.extend({
}
},

initCache: function initCache() {
var app = this;
app.cache = app.config.cache;
if (!app.cache || !app.cache.get) {
app.cache = new Memcached(app.cache || '127.0.0.1:11211');
app.cache.on('failure', function( details ){ app.logger.error( "Server " + details.server + "went down due to: " + details.messages.join( '' ) ) });
app.cache.on('reconnecting', function( details ){ app.logger.debug( "Total downtime caused by server " + details.server + " :" + details.totalDownTime + "ms")});
}
},

initGlobals: function initLogger() {
var app = this;
global.app = app;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"express",
"alternative"
],
"version": "0.1.30",
"version": "0.1.31",
"main": "lighter.js",
"bin": {
"lighter": "commands/cli.js"
Expand Down

0 comments on commit b5143fb

Please sign in to comment.