11const _ = require ( 'lodash' ) ;
2+ const QuickLRU = require ( 'quick-lru' ) ;
3+
24const { validatorGconvert } = require ( '../../../external-services/gprofiler/gconvert' ) ;
35const { getEntitySummary : getNcbiGeneSummary } = require ( '../../../external-services/ncbi' ) ;
46const { getEntitySummary : getHgncSummary } = require ( '../../../external-services/hgnc' ) ;
57const { getEntitySummary : getUniProtSummary } = require ( '../../../external-services/uniprot' ) ;
6- const { NS_HGNC_SYMBOL , NS_NCBI_GENE , NS_UNIPROT , IDENTIFIERS_URL } = require ( '../../../../config' ) ;
7-
8+ const { NS_HGNC_SYMBOL , NS_NCBI_GENE , NS_UNIPROT , IDENTIFIERS_URL , PC_CACHE_MAX_SIZE } = require ( '../../../../config' ) ;
9+ const cache = require ( '../../../cache' ) ;
10+ const pcCache = new QuickLRU ( { maxSize : PC_CACHE_MAX_SIZE } ) ;
811/**
912 * entityFetch: Retrieve EntitySummary for a given id from a datasource
1013 *
1114 * @param { array } localID string(s) that should be fetched
1215 * @return { object } value is EntitySummary keyed by the local ID
1316 */
14- const entityFetch = async ( localIds , dataSource ) => {
17+ const rawEntityFetch = async ( localIds , dataSource ) => {
1518 let eSummary ;
1619 switch ( dataSource ) {
1720 case NS_HGNC_SYMBOL :
@@ -37,7 +40,7 @@ const createUri = ( namespace, localId ) => IDENTIFIERS_URL + '/' + namespace +
3740 * - query: token that has an associated NCBI Gene ID
3841 * - EntitySummary object
3942 */
40- const entitySearch = async tokens => {
43+ const rawEntitySearch = async tokens => {
4144
4245 const results = [ ] ;
4346
@@ -96,4 +99,7 @@ const entitySearch = async tokens => {
9699 return results ;
97100} ;
98101
102+ const entitySearch = cache ( rawEntitySearch , pcCache ) ;
103+ const entityFetch = cache ( rawEntityFetch , pcCache ) ;
104+
99105module . exports = { entitySearch, entityFetch } ;
0 commit comments