aboutsummaryrefslogtreecommitdiffstats
path: root/node_modules/express/node_modules/connect/lib/cache.js
diff options
context:
space:
mode:
authorTeddy Wing2013-04-27 18:20:41 -0400
committerTeddy Wing2013-04-27 18:20:41 -0400
commit4b14305623d5ddc59f435fc5e35c54c0def1d392 (patch)
treeef780015587343a48c46a59a7ccd0263308d062a /node_modules/express/node_modules/connect/lib/cache.js
parent52127aee97d0d16be652d2063c9aefbbef234f43 (diff)
downloadWho-am-I-4b14305623d5ddc59f435fc5e35c54c0def1d392.tar.bz2
Change to node/express app
Diffstat (limited to 'node_modules/express/node_modules/connect/lib/cache.js')
-rw-r--r--node_modules/express/node_modules/connect/lib/cache.js81
1 files changed, 81 insertions, 0 deletions
diff --git a/node_modules/express/node_modules/connect/lib/cache.js b/node_modules/express/node_modules/connect/lib/cache.js
new file mode 100644
index 0000000..052fcdb
--- /dev/null
+++ b/node_modules/express/node_modules/connect/lib/cache.js
@@ -0,0 +1,81 @@
+
+/*!
+ * Connect - Cache
+ * Copyright(c) 2011 Sencha Inc.
+ * MIT Licensed
+ */
+
+/**
+ * Expose `Cache`.
+ */
+
+module.exports = Cache;
+
+/**
+ * LRU cache store.
+ *
+ * @param {Number} limit
+ * @api private
+ */
+
+function Cache(limit) {
+ this.store = {};
+ this.keys = [];
+ this.limit = limit;
+}
+
+/**
+ * Touch `key`, promoting the object.
+ *
+ * @param {String} key
+ * @param {Number} i
+ * @api private
+ */
+
+Cache.prototype.touch = function(key, i){
+ this.keys.splice(i,1);
+ this.keys.push(key);
+};
+
+/**
+ * Remove `key`.
+ *
+ * @param {String} key
+ * @api private
+ */
+
+Cache.prototype.remove = function(key){
+ delete this.store[key];
+};
+
+/**
+ * Get the object stored for `key`.
+ *
+ * @param {String} key
+ * @return {Array}
+ * @api private
+ */
+
+Cache.prototype.get = function(key){
+ return this.store[key];
+};
+
+/**
+ * Add a cache `key`.
+ *
+ * @param {String} key
+ * @return {Array}
+ * @api private
+ */
+
+Cache.prototype.add = function(key){
+ // initialize store
+ var len = this.keys.push(key);
+
+ // limit reached, invalidate LRU
+ if (len > this.limit) this.remove(this.keys.shift());
+
+ var arr = this.store[key] = [];
+ arr.createdAt = new Date;
+ return arr;
+};