1- // @flow
2- import LRU from 'lru-cache' ;
31import type Request from 'express' ;
42import ApplicationRouter from '../../appdev/ApplicationRouter' ;
53import RequestUtils from '../../utils/RequestUtils' ;
64import SearchUtils from '../../utils/SearchUtils' ;
75import Constants from '../../utils/Constants' ;
86
9- const queryToPredictionsCacheOptions = {
10- max : 10000 , // Maximum size of cache
11- maxAge : 1000 * 60 * 60 * 24 * 5 , // Maximum age in milliseconds
12- } ;
13- const queryToPredictionsCache = LRU ( queryToPredictionsCacheOptions ) ;
147const GOOGLE_PLACE = 'googlePlace' ;
158const GOOGLE_PLACE_LOCATION = '42.4440,-76.5019' ;
169
@@ -29,7 +22,7 @@ class SearchRouter extends ApplicationRouter<Array<Object>> {
2922 }
3023
3124 const query = req . body . query . toLowerCase ( ) ;
32- const cachedValue = queryToPredictionsCache . get ( query ) ;
25+ const cachedValue = SearchUtils . queryToPredictionsCache . get ( query ) ;
3326
3427 const formattedStops = await SearchUtils . getFormattedStopsForQuery ( query ) ;
3528
@@ -70,7 +63,7 @@ class SearchRouter extends ApplicationRouter<Array<Object>> {
7063
7164 if ( googlePredictions ) {
7265 const filteredPredictions = getFilteredPredictions ( googlePredictions , formattedStops ) ;
73- queryToPredictionsCache . set ( query , filteredPredictions ) ;
66+ SearchUtils . queryToPredictionsCache . set ( query , filteredPredictions ) ;
7467 return filteredPredictions . concat ( formattedStops ) ;
7568 }
7669 }
0 commit comments