Sha256: 84556af42e5890f13314c58edd1bdf33e1bc98823e8aa8968209af5cdcb81257

Contents?: true

Size: 1.13 KB

Versions: 18

Compression:

Stored size: 1.13 KB

Contents

/*!
 * 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;
};

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma/node_modules/connect/lib/cache.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/connect/lib/cache.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/connect/lib/cache.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/connect/lib/cache.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/connect/lib/cache.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/connect/lib/cache.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/connect/lib/cache.js
hooch-0.0.8 jasmine/node_modules/karma/node_modules/connect/lib/cache.js
hooch-0.0.7 jasmine/node_modules/karma/node_modules/connect/lib/cache.js
hooch-0.0.6 jasmine/node_modules/karma/node_modules/connect/lib/cache.js
entangled-0.0.16 spec/dummy/public/node_modules/karma/node_modules/connect/lib/cache.js
entangled-0.0.15 spec/dummy/public/node_modules/karma/node_modules/connect/lib/cache.js
entangled-0.0.14 spec/dummy/public/node_modules/karma/node_modules/connect/lib/cache.js
entangled-0.0.13 spec/dummy/public/node_modules/karma/node_modules/connect/lib/cache.js
entangled-0.0.12 spec/dummy/public/node_modules/karma/node_modules/connect/lib/cache.js
entangled-0.0.11 spec/dummy/public/node_modules/karma/node_modules/connect/lib/cache.js
entangled-0.0.10 spec/dummy/public/node_modules/karma/node_modules/connect/lib/cache.js
iron_worker_ng-0.10.1 iron_worker_examples/binary/phantom-nodejs/node_modules/phantom/node_modules/express/node_modules/connect/lib/cache.js