I'm working on an application that requires an autocomplete field on a search form. The application is CFML on Railo 3.3. I'm using jQuery UI autocomplete and have implemented the lookup on the server-side like this:
private struct function getStationDetails(required numeric uic)
{
var qryCacheStations = new query();
var qryStations = new query();
var cacheData = "";
var resultData = "";
var stcResult = {};
qryCacheStations.setDatasource(variables.instance['dataSource']);
qryCacheStations.setSQL("select distinct uic, name, crs from stations order by name");
qryCacheStations.setCachedwithin(createTimeSpan(1,0,0,0));
cacheData = qryCacheStations.execute().getResult();
qryStations.setDBType("query");
qryStations.setAttributes(srcTbl = cacheData);
qryStations.setSQL("select name, crs from srcTbl where uic = :uic");
qryStations.addParam(name="uic",value=arguments.uic,CFSQLType="CF_SQL_INTEGER");
resultData = qryStations.execute().getResult();
stcResult = {
name = resultData['name'][1],
crs = resultData['crs'][1]
}
return stcResult;
}
Basically I'm loading the entire station list into the cache on the first lookup, with a 1 day expiry (the data rarely changes), then using a query of queries to return the relevant results back to the client.
My question is simply this; is this agressive caching and QoQs technique a good pattern? Performance seems good and the memory footprint is reasonable (the data set is quite small), so it 'feels' okay but I'm looking for any advice from those who have perhaps tried this before and discovered problems?
Any thoughts would be very much appreciated.