Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[minor] Added some options support and missing expire method.

  • Loading branch information...
commit 6bf4f41c3f269bfec9622ea3ee6c60e1dfebf629 1 parent 8d393b1
@3rd-Eden authored
Showing with 24 additions and 4 deletions.
  1. +24 −4 index.js
View
28 index.js
@@ -5,14 +5,18 @@
*
* @constructor
* @param {Number} expire amount of miliseconds we should cache the data
+ * @param {Object} options options
* @api public
*/
-function Expire(expire) {
+function Expire(expire, options) {
+ options = options || {};
+
this.cache = {};
- this.expire = Expire.parse(expire || '5 minutes');
+ this.expiree = Expire.parse(expire || '5 minutes');
+ this.interval = Expire.parse(options.interval || '2 minutes');
// Start watching for expired items.
- this.start();
+ if (!options.manually) this.start();
}
/**
@@ -54,7 +58,7 @@ Expire.prototype.get = function get(key, dontUpdate) {
Expire.prototype.set = function set(key, value, expires) {
this.cache[key] = {
value: value
- , expires: expires ? Expire.parse(expires) : this.expire
+ , expires: expires ? Expire.parse(expires) : this.expiree
, last: Date.now()
};
@@ -75,6 +79,22 @@ Expire.prototype.has = function has(key) {
};
/**
+ * Expire a key or update it's expiree.
+ *
+ * @param {String} key
+ * @param {Mixed} expire
+ */
+Expire.prototype.expire = function expires(key, expire) {
+ if (!expire) return this.remove(key);
+
+ // we have the key, bump it's expire time.
+ if (this.has(key)) {
+ this.cache[key].expires = Expire.parse(expire);
+ this.cache[key].last = Date.now();
+ }
+};
+
+/**
* Remove an item from the cache.
*
* @param {String} key
Please sign in to comment.
Something went wrong with that request. Please try again.