UNPKG

lol-js

Version:

Node.js bindings for the Riot API, with caching and rate limiting

42 lines (33 loc) 1.07 kB
// Generated by CoffeeScript 1.9.2 (function() { var LRU, LRUCache, ld; ld = require('lodash'); LRU = require('lru-cache'); module.exports = LRUCache = (function() { function LRUCache(options) { this.cache = LRU(options); } LRUCache.prototype.get = function(params, cb) { return setImmediate((function(_this) { return function() { var answer, cacheEntry; if (params.key == null) { cb(new Error("Missing key")); } cacheEntry = _this.cache.get(params.key); if (cacheEntry != null) { answer = (cacheEntry.expires != null) && (Date.now() > cacheEntry.expires) ? null : ld.cloneDeep(cacheEntry.value); } return cb(null, answer); }; })(this)); }; LRUCache.prototype.set = function(params, value) { return this.cache.set(params.key, { expires: params.ttl != null ? Date.now() + params.ttl * 1000 : null, value: ld.cloneDeep(value) }); }; return LRUCache; })(); }).call(this);