diff --git a/src/batch_edge_query.js b/src/batch_edge_query.js index 8f859cfc..0ab96480 100644 --- a/src/batch_edge_query.js +++ b/src/batch_edge_query.js @@ -7,10 +7,11 @@ const utils = require('./utils'); const LogEntry = require('./log_entry'); module.exports = class BatchEdgeQueryHandler { - constructor(kg, resolveOutputIDs = true) { + constructor(kg, resolveOutputIDs = true, options) { this.kg = kg; this.subscribers = []; this.logs = []; + this.caching = options && options.caching; this.resolveOutputIDs = resolveOutputIDs; } @@ -108,7 +109,7 @@ module.exports = class BatchEdgeQueryHandler { async query(qEdges) { const nodeUpdate = new NodesUpdateHandler(qEdges); await nodeUpdate.setEquivalentIDs(qEdges); - const cacheHandler = new CacheHandler(qEdges); + const cacheHandler = new CacheHandler(qEdges, this.caching); const { cachedResults, nonCachedEdges } = await cacheHandler.categorizeEdges(qEdges); this.logs = [...this.logs, ...cacheHandler.logs]; let query_res; diff --git a/src/cache_handler.js b/src/cache_handler.js index 937ddf15..beceaacf 100644 --- a/src/cache_handler.js +++ b/src/cache_handler.js @@ -3,10 +3,12 @@ const debug = require('debug')('bte:biothings-explorer-trapi:cache_handler'); const LogEntry = require('./log_entry'); module.exports = class { - constructor(qEdges, logs = []) { + constructor(qEdges, caching, logs = []) { this.qEdges = qEdges; this.logs = logs; - this.cacheEnabled = !(process.env.REDIS_HOST === undefined) && !(process.env.REDIS_PORT === undefined); + this.cacheEnabled = (caching === 'false') ? + false : + (!(process.env.REDIS_HOST === undefined) && !(process.env.REDIS_PORT === undefined)); this.logs.push( new LogEntry('DEBUG', null, `REDIS cache is ${this.cacheEnabled === true ? '' : 'not'} enabled.`).getLog(), ); diff --git a/src/index.js b/src/index.js index 6d050be0..262dd491 100644 --- a/src/index.js +++ b/src/index.js @@ -81,7 +81,7 @@ exports.TRAPIQueryHandler = class TRAPIQueryHandler { _createBatchEdgeQueryHandlers(queryPaths, kg) { let handlers = {}; for (const index in queryPaths) { - handlers[index] = new BatchEdgeQueryHandler(kg, this.resolveOutputIDs); + handlers[index] = new BatchEdgeQueryHandler(kg, this.resolveOutputIDs, {caching: this.options.caching}); handlers[index].setEdges(queryPaths[index]); handlers[index].subscribe(this.queryResults); handlers[index].subscribe(this.bteGraph);