Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cleaned up code, removed loggingFunction option

  • Loading branch information...
commit 257489d0b9ca45a8bb7cb2ee10d71182eb89df4d 1 parent 7026e74
@tmont tmont authored
View
3  .gitignore
@@ -1,3 +1,2 @@
-.DS_Store
+.idea
node_modules
-*.sock
View
4 .npmignore
@@ -1,4 +0,0 @@
-support
-test
-examples
-*.sock
View
14 History.md
@@ -1,14 +0,0 @@
-0.0.3 / 2012-03-06
-==================
-
- * Rewritten the module due to npm 1.x changes (we now need to pass connect to the function connect-memcached exports in order to extend connect.session.Store:
-
-0.0.2 / 2010-01-03
-==================
-
- * Created basic version that actually works
-
-0.0.1 / 2010-01-03
-==================
-
- * Initial release
View
2  Makefile
@@ -1,2 +0,0 @@
-doc.json: lib/connect-memcached.js
- dox < $< > $@
View
333 doc.json
@@ -1,333 +0,0 @@
-[
- {
- "tags": [],
- "description": {
- "full": "<p>connect-memcached<br />Copyright(c) 2012 Michał Thoma <a href=\"&#109;&#x61;&#x69;l&#116;o:&#x6D;&#105;&#x63;&#104;&#97;&#108;&#64;&#x62;&#97;&#108;&#111;&#114;&#x2E;&#112;&#x6C;\">&#x6D;&#105;&#x63;&#104;&#97;&#108;&#64;&#x62;&#97;&#108;&#111;&#114;&#x2E;&#112;&#x6C;</a><br />MIT Licensed</p>",
- "summary": "<p>connect-memcached<br />Copyright(c) 2012 Michał Thoma <a href=\"&#109;&#97;&#x69;l&#116;&#x6F;:&#x6D;&#105;&#99;&#104;&#x61;&#x6C;&#x40;&#98;&#97;&#108;&#111;&#x72;&#46;&#x70;&#x6C;\">&#x6D;&#105;&#99;&#104;&#x61;&#x6C;&#x40;&#98;&#97;&#108;&#111;&#x72;&#46;&#x70;&#x6C;</a><br />MIT Licensed</p>",
- "body": ""
- },
- "ignore": true
- },
- {
- "tags": [],
- "description": {
- "full": "<p>Library version.</p>",
- "summary": "<p>Library version.</p>",
- "body": ""
- },
- "ignore": false,
- "code": "exports.version = '0.0.3';",
- "ctx": {
- "type": "property",
- "receiver": "exports",
- "name": "version",
- "value": "'0.0.3'",
- "string": "exports.version"
- }
- },
- {
- "tags": [],
- "description": {
- "full": "<p>Module dependencies.</p>",
- "summary": "<p>Module dependencies.</p>",
- "body": ""
- },
- "ignore": false,
- "code": "var Memcached = require('memcached');",
- "ctx": {
- "type": "declaration",
- "name": "Memcached",
- "value": "require('memcached')",
- "string": "Memcached"
- }
- },
- {
- "tags": [],
- "description": {
- "full": "<p>One day in seconds.</p>",
- "summary": "<p>One day in seconds.</p>",
- "body": ""
- },
- "ignore": false,
- "code": "var oneDay = 86400;",
- "ctx": {
- "type": "declaration",
- "name": "oneDay",
- "value": "86400",
- "string": "oneDay"
- }
- },
- {
- "tags": [
- {
- "type": "param",
- "types": [
- "object"
- ],
- "name": "connect",
- "description": ""
- },
- {
- "type": "return",
- "types": [
- "Function"
- ],
- "description": ""
- },
- {
- "type": "api",
- "visibility": "public"
- }
- ],
- "description": {
- "full": "<p>Return the <code>MemcachedStore</code> extending <code>connect</code>'s session Store.</p>",
- "summary": "<p>Return the <code>MemcachedStore</code> extending <code>connect</code>'s session Store.</p>",
- "body": ""
- },
- "isPrivate": false,
- "ignore": false,
- "code": "module.exports = function(connect){",
- "ctx": {
- "type": "method",
- "receiver": "module",
- "name": "exports",
- "string": "module.exports()"
- }
- },
- {
- "tags": [],
- "description": {
- "full": "<p>Connect's Store.</p>",
- "summary": "<p>Connect's Store.</p>",
- "body": ""
- },
- "ignore": false,
- "code": "var Store = connect.session.Store;",
- "ctx": {
- "type": "declaration",
- "name": "Store",
- "value": "connect.session.Store",
- "string": "Store"
- }
- },
- {
- "tags": [
- {
- "type": "param",
- "types": [
- "Object"
- ],
- "name": "options",
- "description": ""
- },
- {
- "type": "api",
- "visibility": "public"
- }
- ],
- "description": {
- "full": "<p>Initialize MemcachedStore with the given <code>options</code>.</p>",
- "summary": "<p>Initialize MemcachedStore with the given <code>options</code>.</p>",
- "body": ""
- },
- "isPrivate": false,
- "ignore": false,
- "code": "function MemcachedStore(options) {\n options = options || {};\n Store.call(this, options);\n if (!options.hosts) {\n options.hosts = '127.0.0.1:11211';\n }\n this.client = new Memcached(options.hosts, options);\n console.log(\"MemcachedStore initialized for servers: \" + options.hosts);\n\n this.client.on(\"issue\", function(issue) {\n console.log(\"MemcachedStore::Issue @ \" + issue.server + \": \" + \n issue.messages + \", \" + issue.retries + \" attempts left\");\n });\n };",
- "ctx": {
- "type": "function",
- "name": "MemcachedStore",
- "string": "MemcachedStore()"
- }
- },
- {
- "tags": [],
- "description": {
- "full": "<p>Inherit from <code>Store</code>.</p>",
- "summary": "<p>Inherit from <code>Store</code>.</p>",
- "body": ""
- },
- "ignore": false,
- "code": "MemcachedStore.prototype.__proto__ = Store.prototype;",
- "ctx": {
- "type": "property",
- "constructor": "MemcachedStore",
- "name": "__proto__",
- "value": "Store.prototype",
- "string": "MemcachedStore.prototype__proto__"
- }
- },
- {
- "tags": [
- {
- "type": "param",
- "types": [
- "String"
- ],
- "name": "sid",
- "description": ""
- },
- {
- "type": "param",
- "types": [
- "Function"
- ],
- "name": "fn",
- "description": ""
- },
- {
- "type": "api",
- "visibility": "public"
- }
- ],
- "description": {
- "full": "<p>Attempt to fetch session by the given <code>sid</code>.</p>",
- "summary": "<p>Attempt to fetch session by the given <code>sid</code>.</p>",
- "body": ""
- },
- "isPrivate": false,
- "ignore": false,
- "code": "MemcachedStore.prototype.get = function(sid, fn) {\n this.client.get(sid, function(err, data) {\n try {\n if (!data) {\n return fn();\n }\n fn(null, JSON.parse(data.toString()));\n } catch (err) {\n fn(err);\n } \n });\n };",
- "ctx": {
- "type": "method",
- "constructor": "MemcachedStore",
- "name": "get",
- "string": "MemcachedStore.prototype.get()"
- }
- },
- {
- "tags": [
- {
- "type": "param",
- "types": [
- "String"
- ],
- "name": "sid",
- "description": ""
- },
- {
- "type": "param",
- "types": [
- "Session"
- ],
- "name": "sess",
- "description": ""
- },
- {
- "type": "param",
- "types": [
- "Function"
- ],
- "name": "fn",
- "description": ""
- },
- {
- "type": "api",
- "visibility": "public"
- }
- ],
- "description": {
- "full": "<p>Commit the given <code>sess</code> object associated with the given <code>sid</code>.</p>",
- "summary": "<p>Commit the given <code>sess</code> object associated with the given <code>sid</code>.</p>",
- "body": ""
- },
- "isPrivate": false,
- "ignore": false,
- "code": "MemcachedStore.prototype.set = function(sid, sess, fn) {\n try {\n var maxAge = sess.cookie.maxAge\n var ttl = 'number' == typeof maxAge ? maxAge / 1000 | 0 : oneDay\n var sess = JSON.stringify(sess);\n\n this.client.set(sid, sess, ttl, function() {\n fn && fn.apply(this, arguments);\n });\n } catch (err) {\n fn && fn(err);\n } \n };",
- "ctx": {
- "type": "method",
- "constructor": "MemcachedStore",
- "name": "set",
- "string": "MemcachedStore.prototype.set()"
- }
- },
- {
- "tags": [
- {
- "type": "param",
- "types": [
- "String"
- ],
- "name": "sid",
- "description": ""
- },
- {
- "type": "api",
- "visibility": "public"
- }
- ],
- "description": {
- "full": "<p>Destroy the session associated with the given <code>sid</code>.</p>",
- "summary": "<p>Destroy the session associated with the given <code>sid</code>.</p>",
- "body": ""
- },
- "isPrivate": false,
- "ignore": false,
- "code": "MemcachedStore.prototype.destroy = function(sid, fn) {\n this.client.del(sid, fn);\n };",
- "ctx": {
- "type": "method",
- "constructor": "MemcachedStore",
- "name": "destroy",
- "string": "MemcachedStore.prototype.destroy()"
- }
- },
- {
- "tags": [
- {
- "type": "param",
- "types": [
- "Function"
- ],
- "name": "fn",
- "description": ""
- },
- {
- "type": "api",
- "visibility": "public"
- }
- ],
- "description": {
- "full": "<p>Fetch number of sessions.</p>",
- "summary": "<p>Fetch number of sessions.</p>",
- "body": ""
- },
- "isPrivate": false,
- "ignore": false,
- "code": "MemcachedStore.prototype.length = function(fn) {\n this.client.items(fn);\n };",
- "ctx": {
- "type": "method",
- "constructor": "MemcachedStore",
- "name": "length",
- "string": "MemcachedStore.prototype.length()"
- }
- },
- {
- "tags": [
- {
- "type": "param",
- "types": [
- "Function"
- ],
- "name": "fn",
- "description": ""
- },
- {
- "type": "api",
- "visibility": "public"
- }
- ],
- "description": {
- "full": "<p>Clear all sessions.</p>",
- "summary": "<p>Clear all sessions.</p>",
- "body": ""
- },
- "isPrivate": false,
- "ignore": false,
- "code": "MemcachedStore.prototype.clear = function(fn) {\n this.client.flush(fn);\n };\n\n return MemcachedStore;\n};",
- "ctx": {
- "type": "method",
- "constructor": "MemcachedStore",
- "name": "clear",
- "string": "MemcachedStore.prototype.clear()"
- }
- }
-]
View
27 lib/connect-memcached.js
@@ -24,8 +24,6 @@ var Memcached = require('memcached');
var oneDay = 86400;
-
-
/**
* Return the `MemcachedStore` extending `connect`'s session Store.
*
@@ -50,8 +48,6 @@ module.exports = function(connect){
*/
function MemcachedStore(options) {
- var log = options.loggingFunction || console.log;
-
options = options || {};
Store.call(this, options);
if (!options.hosts) {
@@ -63,13 +59,7 @@ module.exports = function(connect){
}
this.client = new Memcached(options.hosts, options);
- log("MemcachedStore initialized for servers: " + options.hosts);
-
- this.client.on("issue", function(issue) {
- log("MemcachedStore::Issue @ " + issue.server + ": " +
- issue.messages + ", " + issue.retries + " attempts left");
- });
- };
+ }
/**
* Inherit from `Store`.
@@ -130,8 +120,8 @@ module.exports = function(connect){
sid = this.getKey(sid);
try {
- var maxAge = sess.cookie.maxAge
- var ttl = 'number' == typeof maxAge ? maxAge / 1000 | 0 : oneDay
+ var maxAge = sess.cookie.maxAge;
+ var ttl = 'number' == typeof maxAge ? maxAge / 1000 | 0 : oneDay;
var sess = JSON.stringify(sess);
this.client.set(sid, sess, ttl, function() {
@@ -146,13 +136,12 @@ module.exports = function(connect){
* Destroy the session associated with the given `sid`.
*
* @param {String} sid
+ * @param {Function} fn
* @api public
*/
-
MemcachedStore.prototype.destroy = function(sid, fn) {
- sid = this.getKey(sid);
-
- this.client.del(sid, fn);
+ sid = this.getKey(sid);
+ this.client.del(sid, fn);
};
/**
@@ -163,7 +152,7 @@ module.exports = function(connect){
*/
MemcachedStore.prototype.length = function(fn) {
- this.client.items(fn);
+ this.client.items(fn);
};
/**
@@ -174,7 +163,7 @@ module.exports = function(connect){
*/
MemcachedStore.prototype.clear = function(fn) {
- this.client.flush(fn);
+ this.client.flush(fn);
};
return MemcachedStore;
View
6 package.json
@@ -1,14 +1,14 @@
{
"name": "connect-memcached"
- , "version": "0.0.3"
+ , "version": "0.0.4"
, "description": "Memcached session store for Connect"
, "keywords": ["memcached", "connection", "session", "store", "cache"]
, "author": "Michał Thoma <michal@balor.pl>"
, "repository": {
"type": "git",
- "url": "https://github.com/balor/connect-memcached"
+ "url": "https://github.com/tmont/connect-memcached"
}
- , "dependencies": { "memcached": ">= 0.0.1" }
+ , "dependencies": { "memcached": ">= 0.2.2" }
, "devDependencies": { "connect": ">= 1.4.x" }
, "main": "index"
, "engines": { "node": ">=0.4.7" }
Please sign in to comment.
Something went wrong with that request. Please try again.