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

Add eslint #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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