Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Commit

Permalink
Add eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
alexnault committed Oct 6, 2018
1 parent 243fb34 commit 3a1abcd
Show file tree
Hide file tree
Showing 8 changed files with 1,294 additions and 260 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "airbnb-base"
}
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
'use strict';

module.exports = require('./lib/projection');
module.exports = require('./lib/projection');
30 changes: 14 additions & 16 deletions lib/cache.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
'use strict'

function Cache(ttl) {
this._hash = {};
this._ttl = (ttl) ? ttl : 1000 * 60; // Default to 1 min
};
this._ttl = (ttl) || 1000 * 60; // Default to 1 min
}

// Public
Cache.prototype.get = function(key) {
//console.log(this._cache[key])
Cache.prototype.get = function (key) {
// console.log(this._cache[key])
return (this._hash[key]) ? this._hash[key].v : undefined;
};

// Public
Cache.prototype.set = function(key, value) {
Cache.prototype.set = function (key, value) {
// console.log('Added to cache');
var self = this;
const self = this;

var timeout = setTimeout(function() {
//console.log('timeout reached');
const timeout = setTimeout(() => {
// console.log('timeout reached');
delete self._hash[key];
}, this._ttl);

this._hash[key] = { v: value, t: timeout };
};

// Public
Cache.prototype.del = function(key) {
//console.log('Delete ' + key);
Cache.prototype.del = function (key) {
// console.log('Delete ' + key);
clearTimeout(this._hash[key].t);
delete this._hash[key];
};

// Public
Cache.prototype.clear = function() {
//console.log('Cache cleared');
for (var key in this._hash) {
Cache.prototype.clear = function () {
// console.log('Cache cleared');
for (const key in this._hash) {
clearTimeout(this._hash[key].t);
}
this._hash = {};
};

module.exports = Cache;
module.exports = Cache;
Loading

0 comments on commit 3a1abcd

Please sign in to comment.